@capybara-hq/kernel 0.1.0-rc.105 → 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 +101 -25
- package/dist/conversations/conversations.service.js +132 -32
- package/dist/conversations/events.d.ts +46 -0
- package/dist/conversations/events.js +54 -3
- 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 +34 -13
- package/dist/errors.js +34 -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/http/api.module.js +5 -5
- package/dist/http/request-signal.d.ts +8 -0
- package/dist/http/request-signal.js +14 -0
- 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/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/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/context/build.d.ts +6 -0
- package/dist/runtime/context/build.js +14 -3
- package/dist/runtime/context/compaction.js +15 -5
- 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/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/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 +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
|
@@ -29,6 +29,7 @@ export const COLUMNS = [
|
|
|
29
29
|
"effort",
|
|
30
30
|
"skill",
|
|
31
31
|
"schedule",
|
|
32
|
+
"automation_event",
|
|
32
33
|
"created_at",
|
|
33
34
|
];
|
|
34
35
|
/**
|
|
@@ -80,12 +81,14 @@ export function storedSkill(invokedAs, invoked) {
|
|
|
80
81
|
}
|
|
81
82
|
/**
|
|
82
83
|
* The `user_message` a queued item becomes, as `postUserMessage` would have written it; a scheduled
|
|
83
|
-
* task's item carries its marker (without the stored zone, which is in `context`)
|
|
84
|
+
* task's item carries its marker (without the stored zone, which is in `context`), an event
|
|
85
|
+
* automation's item its event marker.
|
|
84
86
|
*/
|
|
85
87
|
export function queuedUserMessage(r, context = {}) {
|
|
86
88
|
const attachments = r.attachments;
|
|
87
89
|
const skill = r.skill;
|
|
88
90
|
const marker = queuedMarker(r);
|
|
91
|
+
const event = r.automation_event;
|
|
89
92
|
return {
|
|
90
93
|
type: "user_message",
|
|
91
94
|
idemKey: userMessageIdemKey(r.client_message_id),
|
|
@@ -101,6 +104,7 @@ export function queuedUserMessage(r, context = {}) {
|
|
|
101
104
|
clientMessageId: r.client_message_id,
|
|
102
105
|
...(skill !== null && { skill: skill.record }),
|
|
103
106
|
...(marker !== undefined && { schedule: marker }),
|
|
107
|
+
...(event !== null && event !== undefined && { automationEvent: event }),
|
|
104
108
|
},
|
|
105
109
|
};
|
|
106
110
|
}
|
|
@@ -136,7 +140,7 @@ export async function appendQueuedIn(t, eventLog, conversationId, r) {
|
|
|
136
140
|
payload: { ...next, byAccountId: r.account_id, reason: "user" },
|
|
137
141
|
});
|
|
138
142
|
}
|
|
139
|
-
// run context spec §3.4: no browser values were stored with a leftover row;
|
|
143
|
+
// run context spec §3.4: no browser values were stored with a leftover row; an automation's
|
|
140
144
|
// item stored its task's zone, which wins (scheduled tasks spec §6)
|
|
141
145
|
// org-filter: reads the org of the conversation the caller holds the row lock of
|
|
142
146
|
const org = await t
|
|
@@ -30,7 +30,7 @@ export declare class ConversationQueue {
|
|
|
30
30
|
* credentials. The same `clientMessageId` again returns the queued item (`created: false`), or,
|
|
31
31
|
* when it was already sent, the sent `user_message` with `item: null`. Then `ensureRun`: on an
|
|
32
32
|
* idle conversation the item goes out at once. `internal` (kernel callers only, never HTTP): a
|
|
33
|
-
*
|
|
33
|
+
* automation's marker and zone, stored with the item and written with its `user_message`
|
|
34
34
|
* (scheduled tasks spec §6).
|
|
35
35
|
*/
|
|
36
36
|
add(orgId: string, conversationId: string, accountId: string, input: QueueInput, internal?: InternalMessageOptions): Promise<{
|
|
@@ -41,9 +41,9 @@ export declare class ConversationQueue {
|
|
|
41
41
|
private addIn;
|
|
42
42
|
/**
|
|
43
43
|
* Changes a queued item's text (its resources and files stay as queued). A skill invocation's
|
|
44
|
-
* text is its arguments: the skill is rendered again with them now.
|
|
45
|
-
* becomes the person's message: its schedule marker (and the task's zone) is dropped,
|
|
46
|
-
* it triggers is attended (scheduled tasks spec §7).
|
|
44
|
+
* text is its arguments: the skill is rendered again with them now. An automation's item
|
|
45
|
+
* becomes the person's message: its schedule or event marker (and the task's zone) is dropped,
|
|
46
|
+
* so the run it triggers is attended (scheduled tasks spec §7).
|
|
47
47
|
*/
|
|
48
48
|
edit(orgId: string, conversationId: string, accountId: string, itemId: string, text: string): Promise<QueueItem>;
|
|
49
49
|
private editIn;
|
|
@@ -53,7 +53,7 @@ export declare class ConversationQueue {
|
|
|
53
53
|
* Sends a queued item now: it leaves the queue and is posted as a user message in the same
|
|
54
54
|
* transaction (an interjection when a run is active; the items before it keep their place).
|
|
55
55
|
* Racing the dispatcher, exactly one of them takes the item; the loser sees it gone (404). A
|
|
56
|
-
*
|
|
56
|
+
* automation's item is sent as the person's message, without its schedule marker
|
|
57
57
|
* (scheduled tasks spec §7).
|
|
58
58
|
*/
|
|
59
59
|
sendNow(orgId: string, conversationId: string, accountId: string, itemId: string): Promise<ConversationEvent>;
|
|
@@ -10,11 +10,11 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { randomUUID } from "node:crypto";
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
12
|
import { sql } from "kysely";
|
|
13
|
+
import { releaseQueuedTaskRunIn } from "../automations/run-tracker.js";
|
|
13
14
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
14
15
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
15
16
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
16
17
|
import { RunControl as RunControlService } from "../runtime/run-control.js";
|
|
17
|
-
import { releaseQueuedTaskRunIn } from "../schedules/run-tracker.js";
|
|
18
18
|
import { notInvocable } from "../skills/invoke.js";
|
|
19
19
|
import { ConversationsService, NO_REPLY_SKIPS, } from "./conversations.service.js";
|
|
20
20
|
import { EventLog, payloadJson } from "./event-log.js";
|
|
@@ -70,7 +70,7 @@ let ConversationQueue = class ConversationQueue {
|
|
|
70
70
|
* credentials. The same `clientMessageId` again returns the queued item (`created: false`), or,
|
|
71
71
|
* when it was already sent, the sent `user_message` with `item: null`. Then `ensureRun`: on an
|
|
72
72
|
* idle conversation the item goes out at once. `internal` (kernel callers only, never HTTP): a
|
|
73
|
-
*
|
|
73
|
+
* automation's marker and zone, stored with the item and written with its `user_message`
|
|
74
74
|
* (scheduled tasks spec §6).
|
|
75
75
|
*/
|
|
76
76
|
async add(orgId, conversationId, accountId, input, internal = {}) {
|
|
@@ -174,6 +174,7 @@ let ConversationQueue = class ConversationQueue {
|
|
|
174
174
|
timeZone: internal.timeZoneOverride,
|
|
175
175
|
}),
|
|
176
176
|
}),
|
|
177
|
+
automation_event: internal.automationEvent === undefined ? null : JSON.stringify(internal.automationEvent),
|
|
177
178
|
})
|
|
178
179
|
.returning(COLUMNS)
|
|
179
180
|
.executeTakeFirstOrThrow();
|
|
@@ -184,9 +185,9 @@ let ConversationQueue = class ConversationQueue {
|
|
|
184
185
|
}
|
|
185
186
|
/**
|
|
186
187
|
* Changes a queued item's text (its resources and files stay as queued). A skill invocation's
|
|
187
|
-
* text is its arguments: the skill is rendered again with them now.
|
|
188
|
-
* becomes the person's message: its schedule marker (and the task's zone) is dropped,
|
|
189
|
-
* it triggers is attended (scheduled tasks spec §7).
|
|
188
|
+
* text is its arguments: the skill is rendered again with them now. An automation's item
|
|
189
|
+
* becomes the person's message: its schedule or event marker (and the task's zone) is dropped,
|
|
190
|
+
* so the run it triggers is attended (scheduled tasks spec §7).
|
|
190
191
|
*/
|
|
191
192
|
async edit(orgId, conversationId, accountId, itemId, text) {
|
|
192
193
|
const conv = await this.conversations.writable(orgId, conversationId, accountId);
|
|
@@ -214,15 +215,15 @@ let ConversationQueue = class ConversationQueue {
|
|
|
214
215
|
const t = this.db.db;
|
|
215
216
|
const cur = await t
|
|
216
217
|
.selectFrom("conversation_queue")
|
|
217
|
-
.select(["attachments", "files", "content", "skill", "schedule"])
|
|
218
|
+
.select(["attachments", "files", "content", "skill", "schedule", "automation_event"])
|
|
218
219
|
.where("id", "=", itemId)
|
|
219
220
|
.where("conversation_id", "=", conversationId)
|
|
220
221
|
.forUpdate()
|
|
221
222
|
.executeTakeFirst();
|
|
222
223
|
if (!cur)
|
|
223
224
|
throw itemNotFound();
|
|
224
|
-
// a person's words now: the task's run for this item will not happen (
|
|
225
|
-
await releaseQueuedTaskRunIn(t, cur
|
|
225
|
+
// a person's words now: the task's run for this item will not happen (automations §6)
|
|
226
|
+
await releaseQueuedTaskRunIn(t, cur);
|
|
226
227
|
const skill = cur.skill;
|
|
227
228
|
checkText(text, cur.files.length, cur.attachments.length, skill !== null);
|
|
228
229
|
// an invocation's first block is its rendered text: replace it and the record
|
|
@@ -233,6 +234,7 @@ let ConversationQueue = class ConversationQueue {
|
|
|
233
234
|
text: noNul(text),
|
|
234
235
|
// edited by a person: no longer the task's message
|
|
235
236
|
schedule: null,
|
|
237
|
+
automation_event: null,
|
|
236
238
|
updated_at: sql `now()`,
|
|
237
239
|
...(stored !== undefined && {
|
|
238
240
|
skill: stored.skill,
|
|
@@ -258,12 +260,12 @@ let ConversationQueue = class ConversationQueue {
|
|
|
258
260
|
.deleteFrom("conversation_queue")
|
|
259
261
|
.where("id", "=", itemId)
|
|
260
262
|
.where("conversation_id", "=", conversationId)
|
|
261
|
-
.returning(["id", "schedule"])
|
|
263
|
+
.returning(["id", "schedule", "automation_event"])
|
|
262
264
|
.executeTakeFirst();
|
|
263
265
|
if (!gone)
|
|
264
266
|
throw itemNotFound();
|
|
265
|
-
// a task's queued message deleted by a person: its run is skipped (
|
|
266
|
-
await releaseQueuedTaskRunIn(t, gone
|
|
267
|
+
// a task's queued message deleted by a person: its run is skipped (automations §6)
|
|
268
|
+
await releaseQueuedTaskRunIn(t, gone);
|
|
267
269
|
await unpauseIfEmpty(t, conversationId);
|
|
268
270
|
// the wakes an unpause releases for the tree are owed with it (transactional outbox spec §6)
|
|
269
271
|
await this.runs.oweHeldTreeIn(conversationId);
|
|
@@ -272,7 +274,7 @@ let ConversationQueue = class ConversationQueue {
|
|
|
272
274
|
* Sends a queued item now: it leaves the queue and is posted as a user message in the same
|
|
273
275
|
* transaction (an interjection when a run is active; the items before it keep their place).
|
|
274
276
|
* Racing the dispatcher, exactly one of them takes the item; the loser sees it gone (404). A
|
|
275
|
-
*
|
|
277
|
+
* automation's item is sent as the person's message, without its schedule marker
|
|
276
278
|
* (scheduled tasks spec §7).
|
|
277
279
|
*/
|
|
278
280
|
async sendNow(orgId, conversationId, accountId, itemId) {
|
|
@@ -319,8 +321,12 @@ let ConversationQueue = class ConversationQueue {
|
|
|
319
321
|
throw itemNotFound();
|
|
320
322
|
const sent = await alreadySent(t, conversationId, row.client_message_id);
|
|
321
323
|
// sent by a person: their message, not the task's, whose run is skipped
|
|
322
|
-
await releaseQueuedTaskRunIn(t, row
|
|
323
|
-
const out = await appendQueuedIn(t, this.eventLog, conversationId, {
|
|
324
|
+
await releaseQueuedTaskRunIn(t, row);
|
|
325
|
+
const out = await appendQueuedIn(t, this.eventLog, conversationId, {
|
|
326
|
+
...row,
|
|
327
|
+
schedule: null,
|
|
328
|
+
automation_event: null,
|
|
329
|
+
});
|
|
324
330
|
await unpauseIfEmpty(t, conversationId);
|
|
325
331
|
// sent during the run, the item is the author's message like a direct send: it skips the
|
|
326
332
|
// pending questions they may answer (reply-while-question spec §4.2)
|
package/dist/ctx/create-ctx.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { type EmbedClaims, type ExtensionContext, type ExtensionManifest, type ExtensionPointRef, type HttpAccess, type Logger, type RouteCaller, resolveUiSlots, type SetupCheckArgs, type SetupGuidePlace, type ToolHandler, type ToolSpec, type ToolWatcher } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import { type EmbedClaims, type ExtensionContext, type ExtensionManifest, type ExtensionPointRef, type HttpAccess, type Logger, type RouteCaller, resolveUiSlots, type SetupCheckArgs, type SetupGuidePlace, type ToolHandler, type ToolSpec, type ToolWatcher, type TriggerEvent } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import type { Redis } from "ioredis";
|
|
3
3
|
import { Kysely } from "kysely";
|
|
4
|
+
import type { TriggerEventsService } from "../automations/events/trigger-events.service.js";
|
|
4
5
|
import type { DeviceAccessService } from "../device-access/device-access.service.js";
|
|
5
6
|
import type { DialInAccess } from "../dial-in/access.js";
|
|
6
7
|
import { type RegisteredHook } from "../extensions/hooks.js";
|
|
@@ -76,6 +77,12 @@ export interface KernelDeps {
|
|
|
76
77
|
* a test, the CLI): `ctx.deviceAccess` calls are refused.
|
|
77
78
|
*/
|
|
78
79
|
deviceAccess?: () => DeviceAccessBackend | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* What `ctx.triggers` calls through (`TriggerEventsService`), found at the time of use like
|
|
82
|
+
* `deviceAccess`. Absent, or resolving to undefined (a ctx built alone in a test, the CLI):
|
|
83
|
+
* `ctx.triggers.emit` rejects.
|
|
84
|
+
*/
|
|
85
|
+
triggers?: () => TriggersBackend | undefined;
|
|
79
86
|
runWorkers: boolean;
|
|
80
87
|
/** 内核 logger(`debug` 可选:插件 Logger 没有它,测试可不给)。 */
|
|
81
88
|
log: Logger & {
|
|
@@ -84,6 +91,16 @@ export interface KernelDeps {
|
|
|
84
91
|
}
|
|
85
92
|
/** What `ctx.deviceAccess` calls through (`DeviceAccessService`). */
|
|
86
93
|
export type DeviceAccessBackend = Pick<DeviceAccessService, "ensureService" | "request" | "reportBlockedHosts" | "streamTicket" | "addNetworkHosts" | "answerHandoff">;
|
|
94
|
+
/** What `ctx.triggers` calls through (`TriggerEventsService`). */
|
|
95
|
+
export type TriggersBackend = Pick<TriggerEventsService, "emit">;
|
|
96
|
+
/**
|
|
97
|
+
* A plain-data copy of an emitted event, taken once at the ctx boundary (check-then-use): every
|
|
98
|
+
* own enumerable field is read once (a getter cannot change a value after it was validated),
|
|
99
|
+
* prototypes and accessors are dropped. `cause.call` keeps its original reference, since the
|
|
100
|
+
* pipeline's call scope is a symbol-keyed field and the context holds an `AbortSignal`, neither of
|
|
101
|
+
* which a clone keeps; only its scope is read. Data that cannot be cloned is `invalid_event`.
|
|
102
|
+
*/
|
|
103
|
+
export declare function snapshotTriggerEvent(event: TriggerEvent): TriggerEvent;
|
|
87
104
|
/**
|
|
88
105
|
* What `ctx.ui.verifyEmbedToken` returns for a valid token: the signed claims, with an org
|
|
89
106
|
* token's `role` replaced by the caller's role at verification time.
|
|
@@ -209,6 +226,8 @@ export declare class LiveConfig {
|
|
|
209
226
|
* (through `deps.dialIn`; another device throws `ExtensionPermissionError`); `devices` only for
|
|
210
227
|
* an extension that provides `device-provider@1`, `reportChanged` only for a live device bound to
|
|
211
228
|
* this extension (through `deps.devices`; another device throws `ExtensionPermissionError`);
|
|
229
|
+
* `triggers` only with `permissions.triggers`, each emit only of a declared event type, stored
|
|
230
|
+
* in the event's org scope (through `deps.triggers`);
|
|
212
231
|
* `http.route`
|
|
213
232
|
* only the method + path declared in `permissions.http` (the record carries the declared access and
|
|
214
233
|
* its mount, see {@link Route}); `tools.register` only names declared in
|
package/dist/ctx/create-ctx.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEVICE_PROVIDER_EXTENSION_POINT, DeviceAccessError, EXTENSION_POINTS, ExtensionPermissionError, ExtensionPointUnavailableError, FILE_PREVIEW_EXTENSION_POINT, OBJECT_STORE_EXTENSION_POINT, parseExtensionPoint, resolveUiSlots, SETUP_CHECK_ID_RE, SETUP_GUIDE_PLACES, validateFilePreviewProvider, validateToolSpec, } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import { DEVICE_PROVIDER_EXTENSION_POINT, DeviceAccessError, EXTENSION_POINTS, ExtensionPermissionError, ExtensionPointUnavailableError, FILE_PREVIEW_EXTENSION_POINT, OBJECT_STORE_EXTENSION_POINT, parseExtensionPoint, resolveUiSlots, SETUP_CHECK_ID_RE, SETUP_GUIDE_PLACES, TriggerError, validateFilePreviewProvider, validateToolSpec, } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { Command, ConnectionBuilder, ControlledTransactionBuilder, Kysely, TransactionBuilder, } from "kysely";
|
|
3
3
|
import { conversationTopic } from "../conversations/event-log.js";
|
|
4
4
|
import { kernelDb } from "../db/kernel-schema.js";
|
|
@@ -7,6 +7,7 @@ import { enabledExtensionsQuery, isExtensionEnabled } from "../extensions/enable
|
|
|
7
7
|
import { checkHookRegistration } from "../extensions/hooks.js";
|
|
8
8
|
import { RegistrationLedger } from "../extensions/ledger.js";
|
|
9
9
|
import { audit } from "../identity/audit.js";
|
|
10
|
+
import { withOrgScope } from "../infra/database/org-scope.js";
|
|
10
11
|
import { can } from "../orgs/roles.js";
|
|
11
12
|
import { PrefixedStorage } from "../storage/storage.service.js";
|
|
12
13
|
import { canUseSlot, orgUiTopic, PLATFORM_UI_TOPIC, PluginUiRegistration, } from "../ui/registry.js";
|
|
@@ -17,6 +18,39 @@ import { createLock } from "./lock.js";
|
|
|
17
18
|
import { createExtensionNet } from "./net.js";
|
|
18
19
|
import { createQueue } from "./queue.js";
|
|
19
20
|
import { createSecrets } from "./secrets.js";
|
|
21
|
+
/**
|
|
22
|
+
* A plain-data copy of an emitted event, taken once at the ctx boundary (check-then-use): every
|
|
23
|
+
* own enumerable field is read once (a getter cannot change a value after it was validated),
|
|
24
|
+
* prototypes and accessors are dropped. `cause.call` keeps its original reference, since the
|
|
25
|
+
* pipeline's call scope is a symbol-keyed field and the context holds an `AbortSignal`, neither of
|
|
26
|
+
* which a clone keeps; only its scope is read. Data that cannot be cloned is `invalid_event`.
|
|
27
|
+
*/
|
|
28
|
+
export function snapshotTriggerEvent(event) {
|
|
29
|
+
if (typeof event !== "object" || event === null || Array.isArray(event))
|
|
30
|
+
throw new TriggerError("invalid_event", "the event must be an object");
|
|
31
|
+
try {
|
|
32
|
+
const { cause, ...rest } = event;
|
|
33
|
+
const snap = structuredClone(rest);
|
|
34
|
+
if (cause === undefined)
|
|
35
|
+
return snap;
|
|
36
|
+
if (typeof cause !== "object" || cause === null) {
|
|
37
|
+
snap.cause = cause;
|
|
38
|
+
return snap;
|
|
39
|
+
}
|
|
40
|
+
const plain = { ...cause };
|
|
41
|
+
if ("call" in plain) {
|
|
42
|
+
const { call, ...others } = plain;
|
|
43
|
+
snap.cause = { ...structuredClone(others), call };
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
snap.cause = structuredClone(plain);
|
|
47
|
+
}
|
|
48
|
+
return snap;
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
throw new TriggerError("invalid_event", "the event must be plain data", { cause: err });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
20
54
|
/**
|
|
21
55
|
* Queries the names of the extensions enabled in the organization (org config rows plus the
|
|
22
56
|
* required bootstrap plugins, see `extensions/enabled.ts`), not cached.
|
|
@@ -193,6 +227,8 @@ export class LiveConfig {
|
|
|
193
227
|
* (through `deps.dialIn`; another device throws `ExtensionPermissionError`); `devices` only for
|
|
194
228
|
* an extension that provides `device-provider@1`, `reportChanged` only for a live device bound to
|
|
195
229
|
* this extension (through `deps.devices`; another device throws `ExtensionPermissionError`);
|
|
230
|
+
* `triggers` only with `permissions.triggers`, each emit only of a declared event type, stored
|
|
231
|
+
* in the event's org scope (through `deps.triggers`);
|
|
196
232
|
* `http.route`
|
|
197
233
|
* only the method + path declared in `permissions.http` (the record carries the declared access and
|
|
198
234
|
* its mount, see {@link Route}); `tools.register` only names declared in
|
|
@@ -396,6 +432,26 @@ identity = { sha256: null }) {
|
|
|
396
432
|
};
|
|
397
433
|
})()
|
|
398
434
|
: undefined;
|
|
435
|
+
// ctx.triggers: only with permissions.triggers; the event types come from the approved manifest
|
|
436
|
+
// (a frozen copy: the extension changing its manifest object later changes nothing), and the
|
|
437
|
+
// event is stored in its own org's scope (TriggerEventsService checks the rest)
|
|
438
|
+
const triggersApi = perms.triggers
|
|
439
|
+
? (() => {
|
|
440
|
+
const declared = Object.freeze([...(perms.triggers?.emit ?? [])]);
|
|
441
|
+
return {
|
|
442
|
+
emit: async (event) => {
|
|
443
|
+
const b = deps.triggers?.();
|
|
444
|
+
if (!b)
|
|
445
|
+
throw new Error("Trigger events are not available in this process.");
|
|
446
|
+
// one snapshot, read once: what is checked is what is stored
|
|
447
|
+
const snap = snapshotTriggerEvent(event);
|
|
448
|
+
if (typeof snap.orgId !== "string" || snap.orgId === "")
|
|
449
|
+
throw new TriggerError("invalid_event", "invalid event: missing_org_id");
|
|
450
|
+
return withOrgScope(snap.orgId, () => b.emit(name, declared, snap));
|
|
451
|
+
},
|
|
452
|
+
};
|
|
453
|
+
})()
|
|
454
|
+
: undefined;
|
|
399
455
|
// "METHOD path" -> the access the manifest declares for it (the approved manifest)
|
|
400
456
|
const declaredRoutes = new Map((perms.http ?? []).map((r) => [`${r.method} ${r.path}`, r.access]));
|
|
401
457
|
const declaredTools = new Set(perms.tools ?? []);
|
|
@@ -851,7 +907,7 @@ identity = { sha256: null }) {
|
|
|
851
907
|
return closing;
|
|
852
908
|
},
|
|
853
909
|
};
|
|
854
|
-
// secrets / storage / models / dialIn / devices / deviceAccess: a plain property when declared; otherwise a
|
|
910
|
+
// secrets / storage / models / dialIn / devices / deviceAccess / triggers: a plain property when declared; otherwise a
|
|
855
911
|
// non-enumerable getter that throws, so spreading or printing ctx triggers no denial and no audit
|
|
856
912
|
const gated = (key, api, item = `permissions.${key}`) => {
|
|
857
913
|
if (api) {
|
|
@@ -870,6 +926,7 @@ identity = { sha256: null }) {
|
|
|
870
926
|
gated("dialIn", dialInApi);
|
|
871
927
|
gated("devices", devicesApi, `provides ${DEVICE_PROVIDER_EXTENSION_POINT}`);
|
|
872
928
|
gated("deviceAccess", deviceAccessApi);
|
|
929
|
+
gated("triggers", triggersApi);
|
|
873
930
|
return ctx;
|
|
874
931
|
}
|
|
875
932
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { ConversationSource, FileSystemHandle, GitHostEntry, ParsedTheme, PermissionProfile, SandboxBrowseScope, SandboxExecutionRef, SandboxOperationScope, SandboxPermissionSupport, SandboxRoots, SkillInvocation } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import type { ConversationSource, FileSystemHandle, GitHostEntry, ParsedTheme, PermissionProfile, SandboxBrowseScope, SandboxExecutionRef, SandboxOperationScope, SandboxPermissionSupport, SandboxRoots, SkillInvocation, TriggerFactValue, TriggerSubject } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import type { ColumnType, Generated, Kysely } from "kysely";
|
|
3
3
|
import type { ModelRef } from "../agents/definition.js";
|
|
4
|
+
import type { AutomationChat, AutomationEventMarker, AutomationMode, AutomationOrigin, AutomationPauseReason, AutomationPrincipal, AutomationStatus, AutomationTrigger, AutomationUnattendedAsk, ScheduleMarker, TaskRunSkipReason, TaskRunStatus } from "../automations/types.js";
|
|
4
5
|
import type { AccountAvatar } from "../identity/account-avatar.js";
|
|
5
6
|
import type { DeviceNetwork } from "../sandbox/modes.js";
|
|
6
7
|
import type { StartingExecutionGrants } from "../sandbox/operation-authority-types.js";
|
|
@@ -8,7 +9,6 @@ import type { AuthorityEpochVector } from "../sandbox/permission-authority-epoch
|
|
|
8
9
|
import type { PermissionEscalation, PermissionExpansion, PermissionGrantSource, PermissionScopeKind } from "../sandbox/permission-call-types.js";
|
|
9
10
|
import type { PermissionConfigProjection } from "../sandbox/permission-config-publication.js";
|
|
10
11
|
import type { PermissionRuntimeIdentity } from "../sandbox/permission-runtime-reports.js";
|
|
11
|
-
import type { ScheduleChat, ScheduleMarker, ScheduleMode, SchedulePauseReason, ScheduleStatus, ScheduleTrigger, TaskRunSkipReason, TaskRunStatus } from "../schedules/types.js";
|
|
12
12
|
/** 带默认值的时间戳列:插入可省略,读出为 Date。 */
|
|
13
13
|
type Ts = ColumnType<Date, Date | string | undefined, Date | string>;
|
|
14
14
|
type TsNullable = ColumnType<Date | null, Date | string | null | undefined, Date | string | null>;
|
|
@@ -184,7 +184,7 @@ export interface PushRegistrationsTable {
|
|
|
184
184
|
/** A person's switch for one push category (migration 0172); an absent row is on. */
|
|
185
185
|
export interface PushPreferencesTable {
|
|
186
186
|
account_id: string;
|
|
187
|
-
category: "waiting" | "replies" | "tasks" | "
|
|
187
|
+
category: "waiting" | "replies" | "tasks" | "automations";
|
|
188
188
|
enabled: boolean;
|
|
189
189
|
updated_at: Ts;
|
|
190
190
|
}
|
|
@@ -426,8 +426,10 @@ export interface ConversationsTable {
|
|
|
426
426
|
subagent_depth: ColumnType<number, number | undefined, number>;
|
|
427
427
|
/** 0088, renamed in 0105: the device the conversation runs in; null = not chosen yet. */
|
|
428
428
|
device_id: ColumnType<string | null, string | null | undefined, string | null>;
|
|
429
|
-
/** 0113: the
|
|
430
|
-
|
|
429
|
+
/** 0113, renamed in 0188: the automation that created it (`new` mode); null otherwise. */
|
|
430
|
+
automation_id: ColumnType<string | null, string | null | undefined, string | null>;
|
|
431
|
+
/** 0189: the event subject the conversation serves (collaboration spec §4.5); null = none. */
|
|
432
|
+
subject: ColumnType<ConversationSubject | null, string | null | undefined, string | null>;
|
|
431
433
|
/**
|
|
432
434
|
* 0124: where the conversation comes from, set at creation and never changed. Required on insert
|
|
433
435
|
* (the column's `web` default is not relied on: a forgotten source must not read as web).
|
|
@@ -484,16 +486,26 @@ export interface ConversationQueueTable {
|
|
|
484
486
|
/** 0062: the `user_message.skill` record of a queued skill invocation, or null. */
|
|
485
487
|
skill: ColumnType<unknown, string | null | undefined, string | null>;
|
|
486
488
|
/**
|
|
487
|
-
* 0113: the schedule marker of
|
|
489
|
+
* 0113: the schedule marker of an automation's message, plus the task's zone (`timeZone`, the
|
|
488
490
|
* message's zone override; not copied into the logged marker); null for a person's message.
|
|
489
491
|
*/
|
|
490
492
|
schedule: ColumnType<(ScheduleMarker & {
|
|
491
493
|
timeZone?: string;
|
|
492
494
|
}) | null, string | null | undefined, string | null>;
|
|
495
|
+
/** 0189: the event marker of an event automation's message; null otherwise. */
|
|
496
|
+
automation_event: ColumnType<AutomationEventMarker | null, string | null | undefined, string | null>;
|
|
493
497
|
created_at: Ts;
|
|
494
498
|
updated_at: Ts;
|
|
495
499
|
}
|
|
496
500
|
export type TitleSource = "generated" | "manual";
|
|
501
|
+
/** `conversations.subject` (0189): what an event automation's conversation is about. */
|
|
502
|
+
export interface ConversationSubject {
|
|
503
|
+
/** The extension that emitted the subject's events. */
|
|
504
|
+
source: string;
|
|
505
|
+
kind: string;
|
|
506
|
+
id: string;
|
|
507
|
+
title: string;
|
|
508
|
+
}
|
|
497
509
|
/** chat; eval (a hidden full-run replay conversation); subagent (0053: a sub-agent's conversation). */
|
|
498
510
|
export type ConversationKind = "chat" | "eval" | "subagent";
|
|
499
511
|
/** 0006_conversations.sql:会话事件日志,只追加。 */
|
|
@@ -547,10 +559,12 @@ export interface RunsTable {
|
|
|
547
559
|
*/
|
|
548
560
|
budget_run_id: ColumnType<string | null, string | null | undefined, string | null>;
|
|
549
561
|
/**
|
|
550
|
-
* 0113: the
|
|
562
|
+
* 0113, renamed in 0188: the automation run this run serves (set on the run the task's message triggers and
|
|
551
563
|
* inherited by its unattended descendants); null = a person's run.
|
|
552
564
|
*/
|
|
553
|
-
|
|
565
|
+
automation_run_id: ColumnType<string | null, string | null | undefined, string | null>;
|
|
566
|
+
/** 0189: the trigger event an event automation's run serves; null otherwise. */
|
|
567
|
+
trigger_event_id: ColumnType<string | null, string | null | undefined, string | null>;
|
|
554
568
|
/**
|
|
555
569
|
* 0132: a manual compaction run (context compaction spec §4.7): it calls the shared compaction
|
|
556
570
|
* execution with `force: true` instead of the agent loop, and writes no model step.
|
|
@@ -1520,23 +1534,23 @@ export interface ModelUsageTable {
|
|
|
1520
1534
|
}
|
|
1521
1535
|
type NullableText = ColumnType<string | null, string | null | undefined, string | null>;
|
|
1522
1536
|
type NullableTs = ColumnType<Date | null, Date | string | null | undefined, Date | string | null>;
|
|
1523
|
-
/** 0113
|
|
1524
|
-
export interface
|
|
1537
|
+
/** 0113 (renamed in 0188 from the scheduled tasks table): an automation (scheduled tasks spec §4). */
|
|
1538
|
+
export interface AutomationsTable {
|
|
1525
1539
|
id: string;
|
|
1526
1540
|
org_id: string;
|
|
1527
1541
|
account_id: string;
|
|
1528
1542
|
agent_id: string;
|
|
1529
1543
|
name: string;
|
|
1530
1544
|
prompt: string;
|
|
1531
|
-
trigger: ColumnType<
|
|
1532
|
-
mode:
|
|
1545
|
+
trigger: ColumnType<AutomationTrigger, string, string>;
|
|
1546
|
+
mode: AutomationMode;
|
|
1533
1547
|
conversation_id: NullableText;
|
|
1534
|
-
chat: ColumnType<
|
|
1548
|
+
chat: ColumnType<AutomationChat | null, string | null | undefined, string | null>;
|
|
1535
1549
|
model: ColumnType<ModelRef | null, string | null | undefined, string | null>;
|
|
1536
1550
|
effort: NullableText;
|
|
1537
1551
|
device_id: NullableText;
|
|
1538
|
-
status: ColumnType<
|
|
1539
|
-
pause_reason: ColumnType<
|
|
1552
|
+
status: ColumnType<AutomationStatus, AutomationStatus | undefined, AutomationStatus>;
|
|
1553
|
+
pause_reason: ColumnType<AutomationPauseReason | null, AutomationPauseReason | null | undefined, AutomationPauseReason | null>;
|
|
1540
1554
|
paused_by: NullableText;
|
|
1541
1555
|
next_run_at: NullableTs;
|
|
1542
1556
|
jitter_seconds: ColumnType<number, number | undefined, number>;
|
|
@@ -1545,6 +1559,12 @@ export interface ScheduledTasksTable {
|
|
|
1545
1559
|
created_at: Ts;
|
|
1546
1560
|
updated_at: Ts;
|
|
1547
1561
|
deleted_at: NullableTs;
|
|
1562
|
+
/** 0189: who made it (collaboration spec §4.1). */
|
|
1563
|
+
origin: ColumnType<AutomationOrigin, AutomationOrigin | undefined, AutomationOrigin>;
|
|
1564
|
+
/** 0189: whom it acts as; null = the member `account_id` (reserved for agent principals). */
|
|
1565
|
+
principal: ColumnType<AutomationPrincipal | null, string | null | undefined, string | null>;
|
|
1566
|
+
/** 0189: what a question in an unattended run does; null = the default. */
|
|
1567
|
+
unattended_ask: ColumnType<AutomationUnattendedAsk | null, AutomationUnattendedAsk | null | undefined, AutomationUnattendedAsk | null>;
|
|
1548
1568
|
}
|
|
1549
1569
|
/** Why a file share was revoked (0161). */
|
|
1550
1570
|
export type FileShareRevokeReason = "creator" | "admin" | "conversation_deleted" | "member_offboarded" | "creator_lost_access";
|
|
@@ -1584,12 +1604,19 @@ export interface FileSharesTable {
|
|
|
1584
1604
|
created_at: Ts;
|
|
1585
1605
|
updated_at: Ts;
|
|
1586
1606
|
}
|
|
1587
|
-
/**
|
|
1588
|
-
|
|
1607
|
+
/**
|
|
1608
|
+
* 0113 (renamed in 0188 from the scheduled task runs table): one tick, event fire (0189) or trial
|
|
1609
|
+
* run of an automation; unique per (automation, trigger key) when not trial.
|
|
1610
|
+
*/
|
|
1611
|
+
export interface AutomationRunsTable {
|
|
1589
1612
|
id: string;
|
|
1590
|
-
|
|
1613
|
+
/** 0188: renamed from `task_id`. */
|
|
1614
|
+
automation_id: string;
|
|
1591
1615
|
org_id: string;
|
|
1592
|
-
|
|
1616
|
+
/** 0189: nullable; null for an event run. */
|
|
1617
|
+
scheduled_for: ColumnType<Date | null, Date | string | null, Date | string | null>;
|
|
1618
|
+
/** 0189: the tick as `Date.toISOString()` for a time run, the event id for an event run. */
|
|
1619
|
+
trigger_key: string;
|
|
1593
1620
|
fired_at: NullableTs;
|
|
1594
1621
|
trial: ColumnType<boolean, boolean | undefined, boolean>;
|
|
1595
1622
|
/** A person's "run now" (trial or not): runs even while the task is paused. */
|
|
@@ -1600,10 +1627,59 @@ export interface ScheduledTaskRunsTable {
|
|
|
1600
1627
|
skip_reason: ColumnType<TaskRunSkipReason | null, TaskRunSkipReason | null | undefined, TaskRunSkipReason | null>;
|
|
1601
1628
|
error: NullableText;
|
|
1602
1629
|
missing_grants: ColumnType<string[], string | undefined, string>;
|
|
1630
|
+
/** 0189: when the run was recorded (an event run's moment before its claim). */
|
|
1631
|
+
created_at: Ts;
|
|
1603
1632
|
}
|
|
1604
|
-
/**
|
|
1605
|
-
|
|
1606
|
-
|
|
1633
|
+
/**
|
|
1634
|
+
* 0189: an event an extension emitted (`ctx.triggers.emit`, collaboration spec §4.2); unique per
|
|
1635
|
+
* (org, plugin, dedupe key).
|
|
1636
|
+
*/
|
|
1637
|
+
export interface TriggerEventsTable {
|
|
1638
|
+
id: string;
|
|
1639
|
+
org_id: string;
|
|
1640
|
+
plugin: string;
|
|
1641
|
+
type: string;
|
|
1642
|
+
subject: ColumnType<TriggerSubject, string, string>;
|
|
1643
|
+
facts: ColumnType<Record<string, TriggerFactValue>, string | undefined, string>;
|
|
1644
|
+
summary: string;
|
|
1645
|
+
dedupe_key: string;
|
|
1646
|
+
audience: ColumnType<{
|
|
1647
|
+
accountId: string;
|
|
1648
|
+
agentId: string;
|
|
1649
|
+
} | null, string | null | undefined, string | null>;
|
|
1650
|
+
cause_account_id: NullableText;
|
|
1651
|
+
cause_run_id: NullableText;
|
|
1652
|
+
depth: ColumnType<number, number | undefined, number>;
|
|
1653
|
+
state: ColumnType<TriggerEventState, TriggerEventState | undefined, TriggerEventState>;
|
|
1654
|
+
created_at: Ts;
|
|
1655
|
+
}
|
|
1656
|
+
export type TriggerEventState = "pending" | "dispatched" | "undelivered" | "depth_stopped";
|
|
1657
|
+
/**
|
|
1658
|
+
* 0189: an event that reached an automation, and the run that served it (null while it waits:
|
|
1659
|
+
* events of one subject coalesce, collaboration spec §4.7).
|
|
1660
|
+
*/
|
|
1661
|
+
export interface AutomationEventDeliveriesTable {
|
|
1662
|
+
org_id: string;
|
|
1663
|
+
automation_id: string;
|
|
1664
|
+
event_id: string;
|
|
1665
|
+
/** `<subject kind>:<subject id>`. */
|
|
1666
|
+
subject_key: string;
|
|
1667
|
+
automation_run_id: NullableText;
|
|
1668
|
+
created_at: Ts;
|
|
1669
|
+
}
|
|
1670
|
+
/** 0189: the one conversation per subject of a `subject`-mode automation (collaboration §4.5). */
|
|
1671
|
+
export interface AutomationConversationsTable {
|
|
1672
|
+
org_id: string;
|
|
1673
|
+
automation_id: string;
|
|
1674
|
+
subject_kind: string;
|
|
1675
|
+
subject_id: string;
|
|
1676
|
+
conversation_id: string;
|
|
1677
|
+
created_at: Ts;
|
|
1678
|
+
}
|
|
1679
|
+
/** 0113 (renamed in 0188 from the scheduled task grants table): an automation's remembered grants (same shape as `conversation_tool_grants`). */
|
|
1680
|
+
export interface AutomationGrantsTable {
|
|
1681
|
+
/** 0188: renamed from `task_id`. */
|
|
1682
|
+
automation_id: string;
|
|
1607
1683
|
tool_key: string;
|
|
1608
1684
|
spec_hash: string;
|
|
1609
1685
|
connector_id: string | null;
|
|
@@ -1770,9 +1846,12 @@ export interface KernelDatabase {
|
|
|
1770
1846
|
device_projects: DeviceProjectsTable;
|
|
1771
1847
|
device_conversation_notices: DeviceConversationNoticesTable;
|
|
1772
1848
|
background_tasks: BackgroundTasksTable;
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1849
|
+
automations: AutomationsTable;
|
|
1850
|
+
automation_runs: AutomationRunsTable;
|
|
1851
|
+
automation_grants: AutomationGrantsTable;
|
|
1852
|
+
trigger_events: TriggerEventsTable;
|
|
1853
|
+
automation_event_deliveries: AutomationEventDeliveriesTable;
|
|
1854
|
+
automation_conversations: AutomationConversationsTable;
|
|
1776
1855
|
file_shares: FileSharesTable;
|
|
1777
1856
|
platform_icons: PlatformIconsTable;
|
|
1778
1857
|
skills: SkillsTable;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { ApiError } from "../errors.js";
|
|
2
|
+
import type { KernelLogger } from "../log.js";
|
|
3
|
+
import { SandboxService } from "../sandbox/sandbox.service.js";
|
|
4
|
+
import { DeviceProjectsService } from "./device-projects.service.js";
|
|
5
|
+
/**
|
|
6
|
+
* The most project files one message references (composer menus §5); `statAll` checks no more.
|
|
7
|
+
* Defined here (conversations re-export it) so the devices module needs no conversations import.
|
|
8
|
+
*/
|
|
9
|
+
export declare const MAX_PROJECT_FILES = 10;
|
|
10
|
+
/** The most entries one listing answers (composer menus §5). */
|
|
11
|
+
export declare const MAX_PROJECT_FILE_ENTRIES = 200;
|
|
12
|
+
/** One entry of a project directory: `path` is relative to the project root. */
|
|
13
|
+
export interface ProjectFileEntry {
|
|
14
|
+
name: string;
|
|
15
|
+
path: string;
|
|
16
|
+
kind: "file" | "dir";
|
|
17
|
+
/** The file's size in bytes, when the device reports it (a directory listing does not). */
|
|
18
|
+
size?: number;
|
|
19
|
+
}
|
|
20
|
+
/** `GET /devices/:id/projects/:name/files`. */
|
|
21
|
+
export interface ProjectFileList {
|
|
22
|
+
entries: ProjectFileEntry[];
|
|
23
|
+
/** More entries matched than {@link MAX_PROJECT_FILE_ENTRIES} (or than the device listed). */
|
|
24
|
+
truncated: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** The device cannot list its directories for its owner (409 `device.list_unsupported`). */
|
|
27
|
+
export declare const listUnsupported: () => ApiError;
|
|
28
|
+
/**
|
|
29
|
+
* The files of a device's project (composer menus §5): one directory per call, read through the
|
|
30
|
+
* owner browse scope (`SandboxService.ensureRunningForOwner`, then `SandboxService.withBrowse` as
|
|
31
|
+
* the device's owner: metadata only, never file contents, never a write). Every path is relative
|
|
32
|
+
* to the project root and normalized by {@link projectRelativePath} before the device is asked,
|
|
33
|
+
* so the kernel never names a path outside the root; what lies behind a symlink below it is the
|
|
34
|
+
* provider's and its browse scope's to judge. Only the device's owner reads it (anyone else gets
|
|
35
|
+
* `device.not_found`, from the project lookup).
|
|
36
|
+
*/
|
|
37
|
+
export declare class DeviceProjectFilesService {
|
|
38
|
+
private readonly projects;
|
|
39
|
+
private readonly sandbox;
|
|
40
|
+
private readonly log;
|
|
41
|
+
constructor(projects: Pick<DeviceProjectsService, "resolveForBinding">, sandbox: Pick<SandboxService, "withBrowse" | "ensureRunningForOwner">, log: Pick<KernelLogger, "warn">);
|
|
42
|
+
/**
|
|
43
|
+
* Lists the directory `opts.path` (relative to the project `projectName`, the root when absent)
|
|
44
|
+
* of the owner's device: directories first, then files, each group by name (ignoring case);
|
|
45
|
+
* `opts.q` keeps the names that contain it (case-insensitive). The device is asked for as many
|
|
46
|
+
* entries as the protocol allows, sorted here, then cut to {@link MAX_PROJECT_FILE_ENTRIES}. The
|
|
47
|
+
* browse scope is rooted at the project path (narrowed from the owner's ceiling).
|
|
48
|
+
* Refused with `device.path_outside_project` (before anything is read), `device.not_found`,
|
|
49
|
+
* `device.project_not_found`, `device.list_unsupported`, the device codes of the projects
|
|
50
|
+
* routes (`device.offline`, `device.not_running`, `device.projects_unavailable`) and the
|
|
51
|
+
* `list` refusals of adding a project (`device.project_path_missing`, `…_unreadable`,
|
|
52
|
+
* `…_outside_mode`, `device.project_refused`).
|
|
53
|
+
*/
|
|
54
|
+
list(orgId: string, accountId: string, deviceId: string, projectName: string, opts: {
|
|
55
|
+
path?: string;
|
|
56
|
+
q?: string;
|
|
57
|
+
}, signal?: AbortSignal): Promise<ProjectFileList>;
|
|
58
|
+
/**
|
|
59
|
+
* Which of `paths` (relative to the project rooted at `projectPath`) are not files the device
|
|
60
|
+
* reports, asked with `stat` inside one owner browse of the conversation owner's device: a
|
|
61
|
+
* missing path, a directory or one the browse scope refuses counts as missing. Each path is
|
|
62
|
+
* normalized first ({@link projectFilePath}; one that leaves the project or names its root is
|
|
63
|
+
* refused with `device.path_outside_project` before the device is asked); `missing` holds the
|
|
64
|
+
* normalized paths. The browse scope is rooted at `projectPath`, which must be absolute and normalized
|
|
65
|
+
* (an internal error otherwise), and at most {@link MAX_PROJECT_FILES} paths are checked (more
|
|
66
|
+
* is an internal error: the send route bounds them first). The device codes of {@link list}
|
|
67
|
+
* pass on as they are.
|
|
68
|
+
*/
|
|
69
|
+
statAll(ctx: {
|
|
70
|
+
orgId: string;
|
|
71
|
+
accountId: string;
|
|
72
|
+
deviceId: string;
|
|
73
|
+
}, projectPath: string, paths: string[], signal?: AbortSignal): Promise<{
|
|
74
|
+
missing: string[];
|
|
75
|
+
}>;
|
|
76
|
+
/** The owner's project (`resolveForBinding`); a device that offers no listing → `list_unsupported`. */
|
|
77
|
+
private project;
|
|
78
|
+
/**
|
|
79
|
+
* Runs `fn` in the owner browse of the device (`ensureRunningForOwner` first, so a stopped device
|
|
80
|
+
* is started for its owner), its scope rooted at `root` (the project path; narrowed from the
|
|
81
|
+
* owner's ceiling, never wider, `device.project_outside_mode` when they do not meet, checked
|
|
82
|
+
* before the device is started), mapped
|
|
83
|
+
* like the projects routes: kernel refusals stay, a provider
|
|
84
|
+
* without owner browsing is `device.list_unsupported`, an offline machine `device.offline`, an
|
|
85
|
+
* unreachable provider and anything else `device.projects_unavailable`, never a 500.
|
|
86
|
+
*/
|
|
87
|
+
private onDevice;
|
|
88
|
+
}
|