@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
package/dist/channels/threads.js
CHANGED
|
@@ -150,7 +150,7 @@ export async function insertThread(db, k, conversationId) {
|
|
|
150
150
|
}
|
|
151
151
|
/**
|
|
152
152
|
* The live conversation of a thread, or a new one bound to it, inside the caller's transaction
|
|
153
|
-
* (
|
|
153
|
+
* (an automation posting into a chat, scheduled tasks spec §6): the live thread row's
|
|
154
154
|
* conversation when there is one; otherwise `create()`'s conversation, bound with
|
|
155
155
|
* {@link insertThread} and given the chat as its delivery target (`channel_deliveries`), as an
|
|
156
156
|
* inbound message would. When a concurrent inbound bound the thread first, the empty conversation
|
package/dist/config/schema.d.ts
CHANGED
|
@@ -248,11 +248,15 @@ export declare const KernelConfigSchema: z.ZodObject<{
|
|
|
248
248
|
timeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
249
249
|
}, z.core.$strict>>;
|
|
250
250
|
}, z.core.$strict>>;
|
|
251
|
-
|
|
251
|
+
automations: z.ZodPrefault<z.ZodObject<{
|
|
252
252
|
minIntervalFloorMinutes: z.ZodDefault<z.ZodNumber>;
|
|
253
253
|
maxTasksPerMemberCap: z.ZodDefault<z.ZodNumber>;
|
|
254
254
|
maxTasksPerOrgCap: z.ZodDefault<z.ZodNumber>;
|
|
255
255
|
maxRunsPerHourCap: z.ZodDefault<z.ZodNumber>;
|
|
256
|
+
maxEventDepthCap: z.ZodDefault<z.ZodNumber>;
|
|
257
|
+
coalesceSecondsCap: z.ZodDefault<z.ZodNumber>;
|
|
258
|
+
maxEventRunsPerSubjectPerHourCap: z.ZodDefault<z.ZodNumber>;
|
|
259
|
+
eventRetentionDays: z.ZodDefault<z.ZodNumber>;
|
|
256
260
|
}, z.core.$strict>>;
|
|
257
261
|
sandbox: z.ZodPrefault<z.ZodObject<{
|
|
258
262
|
image: z.ZodOptional<z.ZodString>;
|
package/dist/config/schema.js
CHANGED
|
@@ -859,7 +859,9 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
859
859
|
.int()
|
|
860
860
|
.positive()
|
|
861
861
|
.default(60000)
|
|
862
|
-
.meta(meta({
|
|
862
|
+
.meta(meta({
|
|
863
|
+
description: "Timeout of one tool call in milliseconds; also the deadline of a trigger source's events() and visible() calls when an event is dispatched",
|
|
864
|
+
})),
|
|
863
865
|
maxTimeoutMs: z
|
|
864
866
|
.number()
|
|
865
867
|
.int()
|
|
@@ -1433,7 +1435,7 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
1433
1435
|
.prefault({}),
|
|
1434
1436
|
})
|
|
1435
1437
|
.prefault({}),
|
|
1436
|
-
|
|
1438
|
+
automations: z
|
|
1437
1439
|
.strictObject({
|
|
1438
1440
|
minIntervalFloorMinutes: z
|
|
1439
1441
|
.number()
|
|
@@ -1442,7 +1444,7 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
1442
1444
|
.default(5)
|
|
1443
1445
|
.meta(meta({
|
|
1444
1446
|
hot: true,
|
|
1445
|
-
description: "Smallest value an organization may set for the minimum gap between two fire times of
|
|
1447
|
+
description: "Smallest value an organization may set for the minimum gap between two fire times of an automation, in minutes; a lower org value is clamped up to it",
|
|
1446
1448
|
})),
|
|
1447
1449
|
maxTasksPerMemberCap: z
|
|
1448
1450
|
.number()
|
|
@@ -1451,7 +1453,7 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
1451
1453
|
.default(100)
|
|
1452
1454
|
.meta(meta({
|
|
1453
1455
|
hot: true,
|
|
1454
|
-
description: "Largest number of
|
|
1456
|
+
description: "Largest number of automations per member an organization may allow; a higher org value is clamped down to it",
|
|
1455
1457
|
})),
|
|
1456
1458
|
maxTasksPerOrgCap: z
|
|
1457
1459
|
.number()
|
|
@@ -1460,7 +1462,7 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
1460
1462
|
.default(2000)
|
|
1461
1463
|
.meta(meta({
|
|
1462
1464
|
hot: true,
|
|
1463
|
-
description: "Largest number of
|
|
1465
|
+
description: "Largest number of automations per organization an organization may allow; a higher org value is clamped down to it",
|
|
1464
1466
|
})),
|
|
1465
1467
|
maxRunsPerHourCap: z
|
|
1466
1468
|
.number()
|
|
@@ -1469,7 +1471,43 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
1469
1471
|
.default(600)
|
|
1470
1472
|
.meta(meta({
|
|
1471
1473
|
hot: true,
|
|
1472
|
-
description: "Largest
|
|
1474
|
+
description: "Largest value an organization may set for maxRunsPerHour, the automation runs one member's automations may start per hour; a higher org value is clamped down to it",
|
|
1475
|
+
})),
|
|
1476
|
+
maxEventDepthCap: z
|
|
1477
|
+
.number()
|
|
1478
|
+
.int()
|
|
1479
|
+
.positive()
|
|
1480
|
+
.default(16)
|
|
1481
|
+
.meta(meta({
|
|
1482
|
+
hot: true,
|
|
1483
|
+
description: "Largest event chain depth an organization may allow before an event caused by an automation run stops being dispatched; a higher org value is clamped down to it",
|
|
1484
|
+
})),
|
|
1485
|
+
coalesceSecondsCap: z
|
|
1486
|
+
.number()
|
|
1487
|
+
.int()
|
|
1488
|
+
.positive()
|
|
1489
|
+
.default(3600)
|
|
1490
|
+
.meta(meta({
|
|
1491
|
+
hot: true,
|
|
1492
|
+
description: "Longest window, in seconds, an organization may set for coalescing one subject's events into one automation run; a longer org value is clamped down to it",
|
|
1493
|
+
})),
|
|
1494
|
+
maxEventRunsPerSubjectPerHourCap: z
|
|
1495
|
+
.number()
|
|
1496
|
+
.int()
|
|
1497
|
+
.positive()
|
|
1498
|
+
.default(120)
|
|
1499
|
+
.meta(meta({
|
|
1500
|
+
hot: true,
|
|
1501
|
+
description: "Largest value an organization may set for maxEventRunsPerSubjectPerHour: one event automation makes up to that many runs per subject per hour, and a window past it is recorded as a run skipped with subject_rate; a higher org value is clamped down to it",
|
|
1502
|
+
})),
|
|
1503
|
+
eventRetentionDays: z
|
|
1504
|
+
.number()
|
|
1505
|
+
.int()
|
|
1506
|
+
.positive()
|
|
1507
|
+
.default(30)
|
|
1508
|
+
.meta(meta({
|
|
1509
|
+
hot: true,
|
|
1510
|
+
description: "Days a trigger event is kept after it was stored: a dispatched, undelivered or depth-stopped event older than this, none of whose deliveries still waits for a run, is deleted with its deliveries by the trigger event sweep (every five minutes)",
|
|
1473
1511
|
})),
|
|
1474
1512
|
})
|
|
1475
1513
|
.prefault({}),
|
|
@@ -8,8 +8,8 @@ export interface ApprovalProfile {
|
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Resolves the profile that decides an ask addressed to the conversation's person (profiles govern
|
|
11
|
-
* every approval, ruling R1). Only an interactive chat (`kind = 'chat'`, no
|
|
12
|
-
* owner is the person asked has one: any other root,
|
|
11
|
+
* every approval, ruling R1). Only an interactive chat (`kind = 'chat'`, no automation) whose
|
|
12
|
+
* owner is the person asked has one: any other root, an automation's conversation or an ask
|
|
13
13
|
* addressed to another account keeps asking. The profile is the root's effective one as the
|
|
14
14
|
* permission view reads it (Auto falls back to Approve for me where a bound device's consent no
|
|
15
15
|
* longer holds; without a device Auto holds, ruling R8).
|
|
@@ -13,8 +13,8 @@ import { PermissionFacts } from "../sandbox/permission-facts.js";
|
|
|
13
13
|
import { PermissionFactsModule } from "../sandbox/permission-facts.module.js";
|
|
14
14
|
/**
|
|
15
15
|
* Resolves the profile that decides an ask addressed to the conversation's person (profiles govern
|
|
16
|
-
* every approval, ruling R1). Only an interactive chat (`kind = 'chat'`, no
|
|
17
|
-
* owner is the person asked has one: any other root,
|
|
16
|
+
* every approval, ruling R1). Only an interactive chat (`kind = 'chat'`, no automation) whose
|
|
17
|
+
* owner is the person asked has one: any other root, an automation's conversation or an ask
|
|
18
18
|
* addressed to another account keeps asking. The profile is the root's effective one as the
|
|
19
19
|
* permission view reads it (Auto falls back to Approve for me where a bound device's consent no
|
|
20
20
|
* longer holds; without a device Auto holds, ruling R8).
|
|
@@ -36,7 +36,7 @@ let ConversationApprovalProfile = class ConversationApprovalProfile {
|
|
|
36
36
|
.executeTakeFirst();
|
|
37
37
|
if (row === undefined ||
|
|
38
38
|
row.kind !== "chat" ||
|
|
39
|
-
row.
|
|
39
|
+
row.automation_id !== null ||
|
|
40
40
|
row.account_id !== input.requestedFor)
|
|
41
41
|
return null;
|
|
42
42
|
const { view } = await this.facts.viewWithAccess(input.orgId, row.account_id, row);
|
|
@@ -61,6 +61,9 @@ declare const MessageBody: z.ZodObject<{
|
|
|
61
61
|
uri: z.ZodString;
|
|
62
62
|
}, z.core.$strict>>>;
|
|
63
63
|
files: z.ZodOptional<z.ZodArray<z.ZodUUID>>;
|
|
64
|
+
projectFiles: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
65
|
+
path: z.ZodString;
|
|
66
|
+
}, z.core.$strict>>>;
|
|
64
67
|
model: z.ZodOptional<z.ZodObject<{
|
|
65
68
|
provider: z.ZodString;
|
|
66
69
|
model: z.ZodString;
|
|
@@ -102,6 +105,9 @@ export declare const CreateBody: z.ZodObject<{
|
|
|
102
105
|
uri: z.ZodString;
|
|
103
106
|
}, z.core.$strict>>>;
|
|
104
107
|
files: z.ZodOptional<z.ZodArray<z.ZodUUID>>;
|
|
108
|
+
projectFiles: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
109
|
+
path: z.ZodString;
|
|
110
|
+
}, z.core.$strict>>>;
|
|
105
111
|
model: z.ZodOptional<z.ZodObject<{
|
|
106
112
|
provider: z.ZodString;
|
|
107
113
|
model: z.ZodString;
|
|
@@ -270,7 +276,7 @@ export declare class ConversationsController {
|
|
|
270
276
|
tools(principal: Principal, org: OrgContext, id: string, q: z.infer<typeof ToolsQuery>): Promise<{
|
|
271
277
|
tools: ToolInfo[];
|
|
272
278
|
}>;
|
|
273
|
-
postMessage(principal: Principal, org: OrgContext, id: string, body: z.infer<typeof MessageBody
|
|
279
|
+
postMessage(principal: Principal, org: OrgContext, id: string, body: z.infer<typeof MessageBody>, reply: FastifyReply): Promise<{
|
|
274
280
|
event: ConversationEvent;
|
|
275
281
|
}>;
|
|
276
282
|
/**
|
|
@@ -11,6 +11,7 @@ import { isDeviceProjectName } from "@capybara-hq/plugin-sdk";
|
|
|
11
11
|
import { Controller, Delete, Get, Header, HttpCode, Inject, Param, Patch, Post, Res, } from "@nestjs/common";
|
|
12
12
|
import { z } from "zod";
|
|
13
13
|
import { ModelRef } from "../agents/definition.js";
|
|
14
|
+
import { requestSignal } from "../http/request-signal.js";
|
|
14
15
|
import { CurrentPrincipal, requireUser } from "../identity/principal.js";
|
|
15
16
|
import { createZodDto } from "../infra/validation/create-zod-dto.js";
|
|
16
17
|
import { ZBody, ZParam, ZQuery } from "../infra/validation/zod-params.js";
|
|
@@ -19,7 +20,7 @@ import { MAX_ATTACHMENTS } from "../tools/connector-content.js";
|
|
|
19
20
|
import { ConversationToolInfo, TOOL_INFO_KEY_MAX, TOOL_INFO_MAX_KEYS, } from "../tools/info.js";
|
|
20
21
|
import { ARTIFACT_DOWNLOAD_CACHE_SECONDS, ConversationArtifacts, } from "./artifacts.js";
|
|
21
22
|
import { CompactBody, DOWNLOAD_AS, EventsQuery, FilesQuery, IdParams, ListQuery, PatchBody, SubagentsQuery, searchFields, } from "./conversations.schemas.js";
|
|
22
|
-
import { ConversationsService, } from "./conversations.service.js";
|
|
23
|
+
import { ConversationsService, MAX_PROJECT_FILES, } from "./conversations.service.js";
|
|
23
24
|
import { ConversationDeviceStatus } from "./device-status.js";
|
|
24
25
|
import { ConversationFiles, FILE_CONTENT_MAX_BYTES } from "./files.js";
|
|
25
26
|
import { ConversationOutputs, OUTPUT_PAGE_MAX_CHARS } from "./outputs-read.js";
|
|
@@ -69,6 +70,17 @@ const MessageFields = z.object({
|
|
|
69
70
|
* 这里的 100 只是硬上限。
|
|
70
71
|
*/
|
|
71
72
|
files: z.array(z.uuid()).max(100).optional(),
|
|
73
|
+
/**
|
|
74
|
+
* Files of the conversation's device project, by path relative to its root (composer menus §5):
|
|
75
|
+
* checked on the device, never read or uploaded; each becomes a text block after the `@`
|
|
76
|
+
* resources' bodies. A path repeated (after normalization) is referenced once, so
|
|
77
|
+
* `payload.projectFiles` may be shorter than this list. A new conversation needs `project` in
|
|
78
|
+
* the create body.
|
|
79
|
+
*/
|
|
80
|
+
projectFiles: z
|
|
81
|
+
.array(z.object({ path: z.string().min(1).max(4096) }).strict())
|
|
82
|
+
.max(MAX_PROJECT_FILES)
|
|
83
|
+
.optional(),
|
|
72
84
|
/** Switch the conversation's model from the next run (UI refresh B); the agent's own = back. */
|
|
73
85
|
model: ModelRef.strict().optional(),
|
|
74
86
|
/** Switch the effort: one of the (selected) model's declared `effort` values. */
|
|
@@ -97,15 +109,16 @@ const MessageFields = z.object({
|
|
|
97
109
|
/** The sender's UI language (run context spec §3.4). */
|
|
98
110
|
locale: z.enum(["zh", "en"]).optional(),
|
|
99
111
|
});
|
|
100
|
-
// The body of `@` resource i is `content[i + 1]
|
|
101
|
-
//
|
|
102
|
-
// skill, so its text (the arguments) may
|
|
112
|
+
// The body of `@` resource i is `content[i + 1]` and project file i's block follows them, so
|
|
113
|
+
// `content[0]` must be the user's text: with `@` resources or project files the text must not be
|
|
114
|
+
// empty. A skill invocation's `content[0]` is the rendered skill, so its text (the arguments) may
|
|
115
|
+
// be empty.
|
|
103
116
|
const textRule = [
|
|
104
117
|
(b) => b.text.length > 0 ||
|
|
105
118
|
b.skill !== undefined ||
|
|
106
|
-
((b.files?.length ?? 0) > 0 && !b.attachments?.length),
|
|
119
|
+
((b.files?.length ?? 0) > 0 && !b.attachments?.length && !b.projectFiles?.length),
|
|
107
120
|
{
|
|
108
|
-
message: "Text is required unless the message invokes a skill or carries files (and no @ resources)",
|
|
121
|
+
message: "Text is required unless the message invokes a skill or carries files (and no @ resources or project files)",
|
|
109
122
|
path: ["text"],
|
|
110
123
|
},
|
|
111
124
|
];
|
|
@@ -213,12 +226,13 @@ let ConversationsController = class ConversationsController {
|
|
|
213
226
|
clientMessageId: m.clientMessageId,
|
|
214
227
|
...(m.attachments !== undefined && { attachments: m.attachments }),
|
|
215
228
|
...(m.files !== undefined && { files: m.files }),
|
|
229
|
+
...(m.projectFiles !== undefined && { projectFiles: m.projectFiles }),
|
|
216
230
|
...(m.model !== undefined && { model: m.model }),
|
|
217
231
|
...(m.effort !== undefined && { effort: m.effort }),
|
|
218
232
|
...(m.skill !== undefined && { skill: m.skill }),
|
|
219
233
|
...(m.timeZone !== undefined && { timeZone: m.timeZone }),
|
|
220
234
|
...(m.locale !== undefined && { locale: m.locale }),
|
|
221
|
-
}, pick, { source: "web" });
|
|
235
|
+
}, pick, { source: "web", signal: requestSignal(reply) });
|
|
222
236
|
reply.status(out.created ? 201 : 200);
|
|
223
237
|
return { conversation: out.conversation, event: out.event, events: out.events };
|
|
224
238
|
}
|
|
@@ -418,7 +432,7 @@ let ConversationsController = class ConversationsController {
|
|
|
418
432
|
const p = requireUser(principal);
|
|
419
433
|
return { tools: await this.toolInfo.get(org.orgId, id, p.account.id, q.keys) };
|
|
420
434
|
}
|
|
421
|
-
async postMessage(principal, org, id, body) {
|
|
435
|
+
async postMessage(principal, org, id, body, reply) {
|
|
422
436
|
const p = requireUser(principal);
|
|
423
437
|
return {
|
|
424
438
|
event: await this.conversations.postUserMessage(org.orgId, id, p.account.id, {
|
|
@@ -426,13 +440,14 @@ let ConversationsController = class ConversationsController {
|
|
|
426
440
|
...(body.clientMessageId !== undefined && { clientMessageId: body.clientMessageId }),
|
|
427
441
|
...(body.attachments !== undefined && { attachments: body.attachments }),
|
|
428
442
|
...(body.files !== undefined && { files: body.files }),
|
|
443
|
+
...(body.projectFiles !== undefined && { projectFiles: body.projectFiles }),
|
|
429
444
|
...(body.model !== undefined && { model: body.model }),
|
|
430
445
|
...(body.effort !== undefined && { effort: body.effort }),
|
|
431
446
|
...(body.retryOf !== undefined && { retryOf: body.retryOf }),
|
|
432
447
|
...(body.skill !== undefined && { skill: body.skill }),
|
|
433
448
|
...(body.timeZone !== undefined && { timeZone: body.timeZone }),
|
|
434
449
|
...(body.locale !== undefined && { locale: body.locale }),
|
|
435
|
-
}),
|
|
450
|
+
}, requestSignal(reply)),
|
|
436
451
|
};
|
|
437
452
|
}
|
|
438
453
|
/**
|
|
@@ -638,7 +653,8 @@ __decorate([
|
|
|
638
653
|
__param(0, CurrentPrincipal()),
|
|
639
654
|
__param(1, CurrentOrg()),
|
|
640
655
|
__param(2, Param("id")),
|
|
641
|
-
__param(3, ZBody(ConversationMessageBodyDto))
|
|
656
|
+
__param(3, ZBody(ConversationMessageBodyDto)),
|
|
657
|
+
__param(4, Res({ passthrough: true }))
|
|
642
658
|
], ConversationsController.prototype, "postMessage", null);
|
|
643
659
|
__decorate([
|
|
644
660
|
Get(":id/queue"),
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type { ConversationSource } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import type { ConversationSource, TriggerSubject } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { AgentLookup } from "../agents/agent-lookup.js";
|
|
3
3
|
import type { ModelRef } from "../agents/definition.js";
|
|
4
4
|
import type { AgentAvatarView } from "../agents/profile.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { AutomationEventMarker, ScheduleMarker } from "../automations/types.js";
|
|
6
|
+
import type { ConversationSubject, TitleSource } from "../db/kernel-schema.js";
|
|
6
7
|
import { ConversationDevices, type NewConversationDevice } from "../devices/conversation-devices.js";
|
|
8
|
+
import { DeviceProjectFilesService } from "../devices/device-project-files.service.js";
|
|
7
9
|
import { DeviceProjectsService } from "../devices/device-projects.service.js";
|
|
8
10
|
import { type PersonRef } from "../identity/account-avatar.js";
|
|
9
11
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
@@ -13,7 +15,6 @@ import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
|
13
15
|
import { ProviderRegistry } from "../runtime/providers.js";
|
|
14
16
|
import { RunDeletion } from "../runtime/run-deletion.js";
|
|
15
17
|
import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
|
|
16
|
-
import type { ScheduleMarker } from "../schedules/types.js";
|
|
17
18
|
import { type RenderedInvocation, SkillInvoker } from "../skills/invoke.js";
|
|
18
19
|
import { type ApprovalRecord, ApprovalsService } from "../tools/approvals.service.js";
|
|
19
20
|
import { ConnectorContent } from "../tools/connector-content.js";
|
|
@@ -54,8 +55,13 @@ export interface ConversationView {
|
|
|
54
55
|
* sub-agent's is null: it works in its root conversation's.
|
|
55
56
|
*/
|
|
56
57
|
deviceId: string | null;
|
|
57
|
-
/** The
|
|
58
|
-
|
|
58
|
+
/** The automation that created it (a `new`-mode task's run); null otherwise (spec §4). */
|
|
59
|
+
automationId: string | null;
|
|
60
|
+
/**
|
|
61
|
+
* The event subject it serves (a `subject`-mode automation's conversation, collaboration spec
|
|
62
|
+
* §4.5): the emitting extension and the subject; null for any other conversation.
|
|
63
|
+
*/
|
|
64
|
+
subject: ConversationSubject | null;
|
|
59
65
|
/**
|
|
60
66
|
* The device project it is bound to (project root spec §4.3: chosen at creation, never
|
|
61
67
|
* changed), as resolved then: its name and absolute path on the device; null in free mode (a
|
|
@@ -211,7 +217,10 @@ export interface AttachmentRef {
|
|
|
211
217
|
connectorId: string;
|
|
212
218
|
uri: string;
|
|
213
219
|
}
|
|
214
|
-
/**
|
|
220
|
+
/**
|
|
221
|
+
* Resolved `@` resources and referenced project files: the blocks after the user text (the
|
|
222
|
+
* resources' bodies, then one text block per project file) and their metadata.
|
|
223
|
+
*/
|
|
215
224
|
export interface ResolvedExtra {
|
|
216
225
|
blocks: {
|
|
217
226
|
type: "text";
|
|
@@ -224,7 +233,29 @@ export interface ResolvedExtra {
|
|
|
224
233
|
uri: string;
|
|
225
234
|
name: string;
|
|
226
235
|
}[];
|
|
236
|
+
/** The referenced project files (normalized paths), in block order; absent: none. */
|
|
237
|
+
projectFiles?: {
|
|
238
|
+
path: string;
|
|
239
|
+
}[];
|
|
240
|
+
/** The project root the project file blocks name (set with `projectFiles`). */
|
|
241
|
+
projectRoot?: string;
|
|
227
242
|
}
|
|
243
|
+
export { MAX_PROJECT_FILES } from "../devices/device-project-files.service.js";
|
|
244
|
+
/** Where a message's project files are checked: the conversation's device and bound project. */
|
|
245
|
+
export interface ProjectFilesTarget {
|
|
246
|
+
deviceId: string | null;
|
|
247
|
+
project: {
|
|
248
|
+
name: string;
|
|
249
|
+
path: string;
|
|
250
|
+
} | null | undefined;
|
|
251
|
+
/** Stops the check on the device (the request's signal: the client hung up). */
|
|
252
|
+
signal?: AbortSignal | undefined;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* The model-visible text of one referenced project file (composer menus §5): English, logged in
|
|
256
|
+
* the `user_message`, so replay rebuilds it from the log as it is.
|
|
257
|
+
*/
|
|
258
|
+
export declare const projectFileText: (path: string, root: string) => string;
|
|
228
259
|
export { userMessageIdemKey } from "./idem-keys.js";
|
|
229
260
|
/** The longest conversation title (characters, after trimming). */
|
|
230
261
|
export declare const CONVERSATION_TITLE_MAX_CHARS = 120;
|
|
@@ -239,6 +270,13 @@ export interface UserMessageInput {
|
|
|
239
270
|
clientMessageId?: string;
|
|
240
271
|
attachments?: AttachmentRef[];
|
|
241
272
|
files?: string[];
|
|
273
|
+
/**
|
|
274
|
+
* Files of the conversation's device project, referenced by their paths relative to the
|
|
275
|
+
* project root (composer menus §5): checked with `stat`, never read or copied.
|
|
276
|
+
*/
|
|
277
|
+
projectFiles?: {
|
|
278
|
+
path: string;
|
|
279
|
+
}[];
|
|
242
280
|
/** Switch the conversation's model from the next run (the agent's own model = back to it). */
|
|
243
281
|
model?: ModelRef;
|
|
244
282
|
/** Switch the effort (one of the model's declared `effort` values). */
|
|
@@ -265,14 +303,18 @@ export interface UserMessageInput {
|
|
|
265
303
|
im?: ImSenderContext;
|
|
266
304
|
}
|
|
267
305
|
/**
|
|
268
|
-
* Message options only kernel callers pass (
|
|
269
|
-
* an HTTP body: the schedule marker the
|
|
270
|
-
* source of the message's `timeZone`
|
|
306
|
+
* Message options only kernel callers pass (an automation's fire, scheduled tasks spec §6), never
|
|
307
|
+
* an HTTP body: the schedule marker or the event marker (collaboration spec §4.6) the
|
|
308
|
+
* `user_message` carries, and a zone that beats every other source of the message's `timeZone`
|
|
309
|
+
* (`readMessageContext`).
|
|
271
310
|
*/
|
|
272
311
|
export interface InternalMessageOptions {
|
|
273
312
|
initialPermission?: PermissionSelection;
|
|
313
|
+
/** The request's signal: the project file check on the device stops when the client hangs up. */
|
|
314
|
+
signal?: AbortSignal;
|
|
274
315
|
createRequestHash?: string;
|
|
275
316
|
schedule?: ScheduleMarker;
|
|
317
|
+
automationEvent?: AutomationEventMarker;
|
|
276
318
|
timeZoneOverride?: string;
|
|
277
319
|
}
|
|
278
320
|
/** Options of a conversation created by a kernel caller (never an HTTP body). */
|
|
@@ -282,6 +324,14 @@ export interface NewConversationOptions {
|
|
|
282
324
|
* conversation that fell back to `web` would be offered what only the web and DMs may see.
|
|
283
325
|
*/
|
|
284
326
|
source: ConversationSource;
|
|
327
|
+
/**
|
|
328
|
+
* The event subject a `subject`-mode automation's conversation serves (collaboration spec §4.5):
|
|
329
|
+
* `subject` of the subject's trigger events and the emitting extension (`source`), fixed at
|
|
330
|
+
* creation (`conversations.subject`).
|
|
331
|
+
*/
|
|
332
|
+
subject?: TriggerSubject & {
|
|
333
|
+
source: string;
|
|
334
|
+
};
|
|
285
335
|
}
|
|
286
336
|
/**
|
|
287
337
|
* 会话:只有所有者可见;每次访问都实时复核 agent 对所有者仍可用(spec 3.6 R5),
|
|
@@ -309,6 +359,8 @@ export declare class ConversationsService {
|
|
|
309
359
|
private readonly devices;
|
|
310
360
|
/** The project of that device a new conversation is bound to (project root design §4.3). */
|
|
311
361
|
private readonly projects;
|
|
362
|
+
/** Checks a message's referenced project files on the device (composer menus §5). */
|
|
363
|
+
private readonly projectFiles;
|
|
312
364
|
/** A starter's message skips the run's pending questions (reply-while-question spec §8.1). */
|
|
313
365
|
private readonly questions;
|
|
314
366
|
/** ... and its pending network asks (network ask-to-allow spec §6.7). */
|
|
@@ -335,6 +387,8 @@ export declare class ConversationsService {
|
|
|
335
387
|
devices: Pick<ConversationDevices, "forNew">,
|
|
336
388
|
/** The project of that device a new conversation is bound to (project root design §4.3). */
|
|
337
389
|
projects: Pick<DeviceProjectsService, "resolveForBinding">,
|
|
390
|
+
/** Checks a message's referenced project files on the device (composer menus §5). */
|
|
391
|
+
projectFiles: Pick<DeviceProjectFilesService, "statAll">,
|
|
338
392
|
/** A starter's message skips the run's pending questions (reply-while-question spec §8.1). */
|
|
339
393
|
questions: Pick<QuestionsService, "skipPendingIn">,
|
|
340
394
|
/** ... and its pending network asks (network ask-to-allow spec §6.7). */
|
|
@@ -358,8 +412,8 @@ export declare class ConversationsService {
|
|
|
358
412
|
* `agent.not_found` and nothing is written. Queues a run afterwards, like `postUserMessage`.
|
|
359
413
|
* `events` are every event the create wrote, in seq order from seq 1 (a `model_switched` before
|
|
360
414
|
* the message when the send switched), so a client can seed the new conversation's log whole.
|
|
361
|
-
* `internal`: the conversation's source and, for kernel callers only,
|
|
362
|
-
* which also sets `conversations.
|
|
415
|
+
* `internal`: the conversation's source and, for kernel callers only, an automation's marker,
|
|
416
|
+
* which also sets `conversations.automation_id`, and its zone override. `pick.project` binds
|
|
363
417
|
* the conversation to one of its device's projects inside the write ({@link bindingFor}); a
|
|
364
418
|
* retry answers with the conversation the first send created, its binding unchanged.
|
|
365
419
|
*/
|
|
@@ -529,20 +583,32 @@ export declare class ConversationsService {
|
|
|
529
583
|
turnsBefore: number;
|
|
530
584
|
}>;
|
|
531
585
|
/**
|
|
532
|
-
*
|
|
533
|
-
*
|
|
534
|
-
*
|
|
586
|
+
* Appends a user message; a repeated send with the same `clientMessageId` returns the same
|
|
587
|
+
* event. After the write it calls `ensureRun`: with no run in progress it enqueues one; during
|
|
588
|
+
* a run the current run takes the message in between steps, or `ensureRun` runs again when it
|
|
589
|
+
* ends. A failed `ensureRun` is logged, not thrown: the message's transaction owes the ensure-run
|
|
535
590
|
* backstop, which starts the run once the queue is reachable (transactional outbox spec §6).
|
|
536
591
|
*
|
|
537
|
-
* `attachments
|
|
538
|
-
*
|
|
539
|
-
*
|
|
592
|
+
* `attachments` (`@` resource references): the kernel reads each resource with the sender's
|
|
593
|
+
* credentials (redacted, length-capped) and writes it as an extra text block after the user's
|
|
594
|
+
* text in the same user_message, with its metadata in `payload.attachments` (attachment i is
|
|
595
|
+
* `content[i + 1]`). A failed read writes nothing. A repeated send with the same
|
|
596
|
+
* `clientMessageId` returns the written event without reading again.
|
|
597
|
+
*
|
|
598
|
+
* `files` (uploaded attachment ids): checked and bound to this conversation in the transaction
|
|
599
|
+
* that writes the event (see {@link BindFiles}) and appended last as image / document reference
|
|
600
|
+
* blocks (after the `@` resource blocks); any unavailable file writes nothing. The log holds
|
|
601
|
+
* only references, never bytes. With empty `text` (files only: the HTTP layer ensures `files`
|
|
602
|
+
* and no `@` resources then) no text block is written.
|
|
540
603
|
*
|
|
541
|
-
* `
|
|
542
|
-
*
|
|
543
|
-
*
|
|
604
|
+
* `projectFiles` (composer menus §5): checked in the conversation's stored project before the
|
|
605
|
+
* write ({@link resolveExtra}); one block each after the `@` resources' bodies, before the
|
|
606
|
+
* uploaded files' blocks, and `payload.projectFiles`. Any refusal writes nothing; a repeated
|
|
607
|
+
* send with the same `clientMessageId` returns the written event without checking again.
|
|
544
608
|
*/
|
|
545
|
-
postUserMessage(orgId: string, conversationId: string, accountId: string, input: UserMessageInput
|
|
609
|
+
postUserMessage(orgId: string, conversationId: string, accountId: string, input: UserMessageInput,
|
|
610
|
+
/** The request's signal: the project file check on the device stops when the client hangs up. */
|
|
611
|
+
signal?: AbortSignal): Promise<ConversationEvent>;
|
|
546
612
|
/**
|
|
547
613
|
* Writes a message in one transaction: binds its files, reads its sender context and appends it
|
|
548
614
|
* (after its `model_switched` when it switches).
|
|
@@ -610,10 +676,20 @@ export declare class ConversationsService {
|
|
|
610
676
|
*/
|
|
611
677
|
prepareQueuedSkill(orgId: string, conv: ConversationView, accountId: string, input: Pick<UserMessageInput, "skill" | "text">): Promise<RenderedInvocation | undefined>;
|
|
612
678
|
/**
|
|
613
|
-
* Reads the `@` resources with the sender's credentials
|
|
614
|
-
* with the queue, which reads
|
|
615
|
-
|
|
616
|
-
|
|
679
|
+
* Reads the `@` resources with the sender's credentials and checks the referenced project files
|
|
680
|
+
* (nothing when there are none). Shared with the queue, which reads the resources when a
|
|
681
|
+
* message is queued (decision 15; a queued message carries no project files).
|
|
682
|
+
*
|
|
683
|
+
* Project files (composer menus §5) are checked in `target`'s project on its device as the
|
|
684
|
+
* sender (the conversation's owner, through `DeviceProjectFilesService.statAll`, outside any
|
|
685
|
+
* transaction): no bound project → `conversation.project_file_unavailable` with `reason:
|
|
686
|
+
* "no_project"`; a path leaving the project → `device.path_outside_project`; one that is not a
|
|
687
|
+
* file there → `conversation.project_file_unavailable` with its path; the device codes pass on.
|
|
688
|
+
* Each becomes a {@link projectFileText} block after the resources' bodies.
|
|
689
|
+
*/
|
|
690
|
+
resolveExtra(orgId: string, accountId: string, input: Pick<UserMessageInput, "attachments" | "projectFiles">, target?: ProjectFilesTarget): Promise<ResolvedExtra>;
|
|
691
|
+
/** {@link resolveExtra}'s project file check: the normalized paths and the root, or none. */
|
|
692
|
+
private checkProjectFiles;
|
|
617
693
|
/**
|
|
618
694
|
* Binds uploaded files inside the message's (or queue item's) transaction; none → no blocks.
|
|
619
695
|
* The bound files join the conversation's files, so open pages read the list again after the
|