@capybara-hq/kernel 0.1.0-rc.23 → 0.1.0-rc.25
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/bootstrap.json +25 -25
- package/dist/admin/admin.module.d.ts +2 -1
- package/dist/admin/admin.module.js +9 -3
- package/dist/admin/health.service.d.ts +2 -2
- package/dist/admin/health.service.js +6 -2
- package/dist/admin/outbox-dead.controller.d.ts +23 -0
- package/dist/admin/outbox-dead.controller.js +62 -0
- package/dist/admin/outbox-dead.schemas.d.ts +8 -0
- package/dist/admin/outbox-dead.schemas.js +18 -0
- package/dist/admin/outbox-dead.service.d.ts +66 -0
- package/dist/admin/outbox-dead.service.js +179 -0
- package/dist/admin/overview.service.d.ts +40 -5
- package/dist/admin/overview.service.js +41 -7
- package/dist/agents/agents.module.js +3 -0
- package/dist/agents/agents.service.d.ts +6 -1
- package/dist/agents/agents.service.js +11 -2
- package/dist/agents/from-template.js +1 -1
- package/dist/background/finish.d.ts +5 -2
- package/dist/background/finish.js +14 -3
- package/dist/background/launch.d.ts +2 -1
- package/dist/background/launch.js +5 -2
- package/dist/background/store.d.ts +8 -0
- package/dist/background/store.js +24 -0
- package/dist/catalog/admin-catalog.controller.d.ts +21 -2
- package/dist/catalog/admin-catalog.controller.js +45 -6
- package/dist/catalog/admin-catalog.schemas.d.ts +5 -0
- package/dist/catalog/admin-catalog.schemas.js +8 -0
- package/dist/catalog/catalog-import.module.js +0 -4
- package/dist/catalog/catalog-scope.service.d.ts +63 -26
- package/dist/catalog/catalog-scope.service.js +146 -71
- package/dist/catalog/catalog.module.d.ts +2 -1
- package/dist/catalog/catalog.module.js +9 -4
- package/dist/catalog/catalog.service.d.ts +11 -4
- package/dist/catalog/catalog.service.js +21 -5
- package/dist/catalog/cli.d.ts +4 -3
- package/dist/catalog/cli.js +8 -13
- package/dist/catalog/job-ids.d.ts +8 -20
- package/dist/catalog/job-ids.js +11 -16
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-plugin-uploads.d.ts +11 -4
- package/dist/catalog/org-plugin-uploads.js +21 -6
- package/dist/catalog/owned-items.d.ts +6 -13
- package/dist/catalog/owned-items.js +11 -29
- package/dist/catalog/owned-plugin-cleanup.d.ts +8 -17
- package/dist/catalog/owned-plugin-cleanup.js +12 -66
- package/dist/catalog/platform-components.d.ts +56 -34
- package/dist/catalog/platform-components.js +68 -78
- package/dist/catalog/platform-import-update.d.ts +50 -0
- package/dist/catalog/platform-import-update.js +116 -0
- package/dist/catalog/plugin-import.d.ts +64 -26
- package/dist/catalog/plugin-import.js +113 -77
- package/dist/catalog/plugin-upgrade.d.ts +22 -4
- package/dist/catalog/plugin-upgrade.js +26 -19
- package/dist/catalog/scope-jobs.d.ts +59 -0
- package/dist/catalog/scope-jobs.js +65 -0
- package/dist/catalog/scope-sync-workers.d.ts +22 -0
- package/dist/catalog/scope-sync-workers.js +58 -2
- package/dist/catalog/scope-sync.d.ts +40 -65
- package/dist/catalog/scope-sync.js +114 -122
- package/dist/channels/channels.module.d.ts +5 -2
- package/dist/channels/channels.module.js +9 -2
- package/dist/channels/deliver-job.d.ts +25 -0
- package/dist/channels/deliver-job.js +25 -0
- package/dist/channels/inbound.d.ts +1 -1
- package/dist/channels/inbound.js +4 -17
- package/dist/channels/jobs.d.ts +28 -18
- package/dist/channels/jobs.js +63 -26
- package/dist/channels/threads.d.ts +4 -3
- package/dist/channels/threads.js +4 -3
- package/dist/config/schema.d.ts +0 -3
- package/dist/config/schema.js +11 -20
- package/dist/conversations/agent-tree.d.ts +16 -0
- package/dist/conversations/agent-tree.js +36 -0
- package/dist/conversations/conversations.controller.js +4 -2
- package/dist/conversations/conversations.service.d.ts +61 -19
- package/dist/conversations/conversations.service.js +69 -43
- package/dist/conversations/event-log.d.ts +7 -10
- package/dist/conversations/event-log.js +24 -15
- package/dist/conversations/events.d.ts +21 -0
- package/dist/conversations/events.js +26 -2
- package/dist/conversations/queue.service.d.ts +8 -3
- package/dist/conversations/queue.service.js +37 -13
- package/dist/conversations/source.d.ts +10 -0
- package/dist/conversations/source.js +17 -0
- package/dist/conversations/titles.d.ts +21 -8
- package/dist/conversations/titles.js +42 -15
- package/dist/conversations/tree.d.ts +10 -0
- package/dist/conversations/tree.js +35 -0
- package/dist/db/kernel-schema.d.ts +35 -22
- package/dist/devices/devices.service.d.ts +23 -11
- package/dist/devices/devices.service.js +34 -26
- package/dist/errors.d.ts +11 -0
- package/dist/errors.js +11 -0
- package/dist/evals/run-replay.d.ts +13 -2
- package/dist/evals/run-replay.js +42 -9
- package/dist/evals/snapshot.d.ts +7 -1
- package/dist/evals/snapshot.js +2 -1
- package/dist/extensions/extensions.module.js +3 -0
- package/dist/extensions/hooks.d.ts +22 -3
- package/dist/extensions/hooks.js +15 -1
- package/dist/extensions/lifecycle-hooks.d.ts +99 -0
- package/dist/extensions/lifecycle-hooks.js +273 -0
- package/dist/extensions/lifecycle.d.ts +6 -1
- package/dist/extensions/lifecycle.js +9 -2
- package/dist/extensions/org-config.d.ts +13 -1
- package/dist/extensions/org-config.js +19 -2
- package/dist/extensions/permission-view.d.ts +9 -5
- package/dist/extensions/permission-view.js +9 -4
- package/dist/extensions/point-defaults.d.ts +28 -1
- package/dist/extensions/point-defaults.js +44 -13
- package/dist/extensions/usage-subscribers.d.ts +43 -0
- package/dist/extensions/usage-subscribers.js +108 -0
- package/dist/http/api.module.js +2 -0
- package/dist/inbox/inbox.service.d.ts +6 -20
- package/dist/inbox/inbox.service.js +0 -3
- package/dist/inbox/org-notices.d.ts +1 -1
- package/dist/inbox/platform-inbox.service.d.ts +3 -32
- package/dist/inbox/platform-inbox.service.js +5 -54
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/infra/cli/kernel-cli.module.js +5 -0
- package/dist/infra/events/kernel-events.d.ts +9 -35
- package/dist/infra/outbox/outbox-relay.module.d.ts +6 -0
- package/dist/infra/outbox/outbox-relay.module.js +18 -0
- package/dist/infra/outbox/outbox.dispatcher.d.ts +103 -0
- package/dist/infra/outbox/outbox.dispatcher.js +310 -0
- package/dist/infra/outbox/outbox.module.d.ts +24 -0
- package/dist/infra/outbox/outbox.module.js +50 -0
- package/dist/infra/outbox/outbox.relay.d.ts +31 -0
- package/dist/infra/outbox/outbox.relay.js +76 -0
- package/dist/infra/outbox/outbox.service.d.ts +51 -0
- package/dist/infra/outbox/outbox.service.js +131 -0
- package/dist/infra/outbox/registry.d.ts +244 -0
- package/dist/infra/outbox/registry.js +234 -0
- package/dist/infra/queue/queue-names.d.ts +8 -0
- package/dist/infra/queue/queue-names.js +17 -0
- package/dist/kernel.module.js +3 -0
- package/dist/local-devices/device-policy.service.d.ts +4 -0
- package/dist/local-devices/device-policy.service.js +61 -3
- package/dist/local-devices/machines.d.ts +13 -5
- package/dist/local-devices/machines.js +45 -7
- package/dist/local-devices/policy-summary.d.ts +44 -1
- package/dist/local-devices/policy-summary.js +69 -0
- package/dist/models/embeddings.d.ts +9 -9
- package/dist/models/embeddings.js +11 -18
- package/dist/models/models.module.js +3 -0
- package/dist/orgs/directory-sync.js +1 -1
- package/dist/orgs/members.service.js +1 -1
- package/dist/orgs/offboarding.d.ts +50 -57
- package/dist/orgs/offboarding.js +117 -162
- package/dist/orgs/orgs.module.js +3 -0
- package/dist/orgs/orgs.service.d.ts +11 -5
- package/dist/orgs/orgs.service.js +22 -6
- package/dist/overrides.d.ts +23 -3
- package/dist/overrides.js +12 -2
- package/dist/platform/exclusions.js +5 -0
- package/dist/platform/ops/admin.ops.js +18 -2
- package/dist/platform/ops/catalog-admin.ops.d.ts +3 -1
- package/dist/platform/ops/catalog-admin.ops.js +32 -4
- package/dist/platform/ops/inbox.ops.js +4 -20
- package/dist/platform/ops/outbox.ops.d.ts +21 -0
- package/dist/platform/ops/outbox.ops.js +125 -0
- package/dist/platform/ops/platform.ops.d.ts +1 -0
- package/dist/platform/ops/platform.ops.js +6 -3
- package/dist/platform/ops/schedules.ops.js +40 -1
- package/dist/platform/platform-ops.module.d.ts +2 -1
- package/dist/platform/platform-ops.module.js +3 -0
- package/dist/platform/route-schemas.js +3 -0
- package/dist/roles/worker-role.d.ts +10 -5
- package/dist/roles/worker-role.js +19 -9
- package/dist/roles/worker.module.js +11 -8
- package/dist/runtime/context/build.d.ts +3 -0
- package/dist/runtime/context/build.js +15 -0
- package/dist/runtime/context/plugin-context.d.ts +20 -0
- package/dist/runtime/context/plugin-context.js +30 -0
- package/dist/runtime/langgraph-loop.js +17 -5
- package/dist/runtime/limits.d.ts +15 -0
- package/dist/runtime/limits.js +25 -0
- package/dist/runtime/loop.d.ts +16 -3
- package/dist/runtime/loop.js +2 -1
- package/dist/runtime/maintenance.d.ts +7 -3
- package/dist/runtime/maintenance.js +52 -12
- package/dist/runtime/model-call.d.ts +20 -17
- package/dist/runtime/model-call.js +15 -24
- package/dist/runtime/plugin-context.service.d.ts +69 -0
- package/dist/runtime/plugin-context.service.js +208 -0
- package/dist/runtime/queue-lost-jobs.d.ts +24 -0
- package/dist/runtime/queue-lost-jobs.js +51 -0
- package/dist/runtime/run-control.d.ts +47 -5
- package/dist/runtime/run-control.js +79 -12
- package/dist/runtime/run-finish.d.ts +39 -12
- package/dist/runtime/run-finish.js +97 -14
- package/dist/runtime/run-jobs.d.ts +95 -13
- package/dist/runtime/run-jobs.js +199 -28
- package/dist/runtime/run-orphan-check.job.d.ts +142 -0
- package/dist/runtime/run-orphan-check.job.js +339 -0
- package/dist/runtime/run-processors.d.ts +16 -9
- package/dist/runtime/run-processors.js +1 -1
- package/dist/runtime/run-queue.d.ts +75 -53
- package/dist/runtime/run-queue.js +189 -263
- package/dist/runtime/run-steps.d.ts +1 -2
- package/dist/runtime/run-steps.js +8 -11
- package/dist/runtime/run-worker.d.ts +26 -16
- package/dist/runtime/run-worker.js +132 -37
- package/dist/runtime/runtime.module.d.ts +2 -3
- package/dist/runtime/runtime.module.js +7 -6
- package/dist/runtime/step-log.d.ts +16 -4
- package/dist/runtime/step-log.js +26 -6
- package/dist/runtime/stream.controller.d.ts +2 -4
- package/dist/runtime/stream.controller.js +5 -11
- package/dist/runtime/subagents/child.js +1 -1
- package/dist/runtime/subagents/definition.d.ts +2 -1
- package/dist/runtime/subagents/definition.js +4 -2
- package/dist/runtime/subagents/deliveries.d.ts +6 -3
- package/dist/runtime/subagents/deliveries.js +16 -7
- package/dist/runtime/subagents/dispatch.d.ts +12 -12
- package/dist/runtime/subagents/dispatch.js +14 -38
- package/dist/runtime/subagents/messages.d.ts +5 -1
- package/dist/runtime/subagents/messages.js +11 -3
- package/dist/runtime/subagents/skill-fork.d.ts +3 -3
- package/dist/runtime/subagents/skill-fork.js +8 -5
- package/dist/runtime/subagents/subagents.service.js +1 -1
- package/dist/runtime/subagents/tree-jobs.d.ts +61 -0
- package/dist/runtime/subagents/tree-jobs.js +86 -0
- package/dist/runtime/usage-report-jobs.d.ts +23 -48
- package/dist/runtime/usage-report-jobs.js +67 -119
- package/dist/runtime/usage-report.d.ts +28 -77
- package/dist/runtime/usage-report.js +35 -213
- package/dist/runtime/waits.d.ts +48 -198
- package/dist/runtime/waits.js +103 -805
- package/dist/sandbox/jobs.d.ts +20 -10
- package/dist/sandbox/jobs.js +23 -17
- package/dist/sandbox/sandbox.service.d.ts +17 -4
- package/dist/sandbox/sandbox.service.js +55 -14
- package/dist/schedules/calendar.d.ts +134 -0
- package/dist/schedules/calendar.js +410 -0
- package/dist/schedules/fire.d.ts +26 -7
- package/dist/schedules/fire.js +91 -22
- package/dist/schedules/job-ids.d.ts +66 -17
- package/dist/schedules/job-ids.js +81 -13
- package/dist/schedules/run-tracker.d.ts +0 -5
- package/dist/schedules/run-tracker.js +2 -14
- package/dist/schedules/scan.job.d.ts +13 -32
- package/dist/schedules/scan.job.js +50 -164
- package/dist/schedules/schedule-math.d.ts +42 -0
- package/dist/schedules/schedule-math.js +52 -0
- package/dist/schedules/scheduled-tasks.service.d.ts +22 -6
- package/dist/schedules/scheduled-tasks.service.js +70 -14
- package/dist/schedules/schedules.controller.d.ts +5 -1
- package/dist/schedules/schedules.controller.js +15 -1
- package/dist/schedules/schedules.module.js +0 -4
- package/dist/schedules/schedules.schemas.d.ts +35 -0
- package/dist/schedules/schedules.schemas.js +27 -0
- package/dist/schedules/store.d.ts +5 -0
- package/dist/schedules/store.js +20 -0
- package/dist/skills/changes.controller.d.ts +1 -1
- package/dist/skills/changes.controller.js +1 -1
- package/dist/tools/approvals.service.d.ts +41 -11
- package/dist/tools/approvals.service.js +108 -14
- package/dist/tools/builtin-names.d.ts +5 -3
- package/dist/tools/builtin-names.js +12 -4
- package/dist/tools/builtins/builtin-tools.d.ts +1 -2
- package/dist/tools/builtins/builtin-tools.js +21 -17
- package/dist/tools/builtins/sandbox/bash.js +9 -3
- package/dist/tools/builtins/sandbox/common.d.ts +18 -1
- package/dist/tools/builtins/sandbox/common.js +14 -1
- package/dist/tools/builtins/sandbox/index.d.ts +2 -1
- package/dist/tools/builtins/sandbox/index.js +4 -1
- package/dist/tools/builtins/sandbox/task-list.d.ts +12 -0
- package/dist/tools/builtins/sandbox/task-list.js +130 -0
- package/dist/tools/builtins/sandbox/task-output.d.ts +8 -1
- package/dist/tools/builtins/sandbox/task-output.js +21 -3
- package/dist/tools/builtins/web/extract.d.ts +2 -4
- package/dist/tools/builtins/web/extract.js +2 -5
- package/dist/tools/pipeline.d.ts +12 -3
- package/dist/tools/pipeline.js +6 -1
- package/dist/tools/questions.service.d.ts +30 -10
- package/dist/tools/questions.service.js +41 -27
- package/dist/tools/registry.d.ts +12 -3
- package/dist/tools/registry.js +13 -3
- package/dist/tools/tools.module.js +4 -3
- package/package.json +3 -3
- package/src/migrations/0118_device_policy_ops.sql +6 -0
- package/src/migrations/0119_outbox.sql +22 -0
- package/src/migrations/0120_drop_usage_report_sweep.sql +7 -0
- package/src/migrations/0121_drop_platform_migration_runs.sql +12 -0
- package/src/migrations/0122_drop_scheduled_task_runs_rechecked_at.sql +5 -0
- package/src/migrations/0123_pgvector.sql +27 -0
- package/src/migrations/0124_conversation_source.sql +36 -0
- package/dist/catalog/platform-migration.d.ts +0 -115
- package/dist/catalog/platform-migration.js +0 -583
- package/dist/infra/queue/add-job-once.d.ts +0 -14
- package/dist/infra/queue/add-job-once.js +0 -16
package/dist/channels/jobs.js
CHANGED
|
@@ -11,14 +11,14 @@ import { createHash, randomUUID } from "node:crypto";
|
|
|
11
11
|
import { getQueueToken } from "@nestjs/bullmq";
|
|
12
12
|
import { Inject, Injectable } from "@nestjs/common";
|
|
13
13
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
14
|
+
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
15
|
+
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
14
16
|
import { KernelEvents } from "../infra/events/kernel-events.js";
|
|
17
|
+
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
18
|
+
import { OUTBOX_JOBS } from "../infra/outbox/registry.js";
|
|
15
19
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
16
|
-
|
|
17
|
-
export
|
|
18
|
-
/** 投递任务名。 */
|
|
19
|
-
export const DELIVER_JOB = "deliver";
|
|
20
|
-
/** 投递任务 id(不含 `:`):同一会话、同一日志位置只排一个任务。 */
|
|
21
|
-
export const deliverJobId = (conversationId, seq) => `deliver-${conversationId}-${seq}`;
|
|
20
|
+
import { CHANNEL_QUEUE_NAME, DELIVER_JOB, deliverJobId, oweDelivery, } from "./deliver-job.js";
|
|
21
|
+
export { CHANNEL_QUEUE_NAME, DELIVER_JOB, deliverJobId, oweDelivery, } from "./deliver-job.js";
|
|
22
22
|
/**
|
|
23
23
|
* 结束后复核排的任务 id:每次唯一(带随机后缀,不含 `:`)。不能复用 `deliver-<会话>-<seq>`——同 id 的任务
|
|
24
24
|
* 可能正因锁被占而即将直接结束,BullMQ 会把新任务去重进它,于是没人投递。
|
|
@@ -32,7 +32,7 @@ export function idempotencyKey(raw) {
|
|
|
32
32
|
return createHash("sha256").update(raw).digest("base64url").slice(0, 32);
|
|
33
33
|
}
|
|
34
34
|
/** 可重试失败(限流、5xx、网络、超时)的总尝试次数。 */
|
|
35
|
-
export const DELIVER_ATTEMPTS =
|
|
35
|
+
export const DELIVER_ATTEMPTS = OUTBOX_JOBS.deliver.opts.attempts;
|
|
36
36
|
/** 入站任务名。 */
|
|
37
37
|
export const INBOUND_JOB = "inbound";
|
|
38
38
|
/**
|
|
@@ -40,7 +40,7 @@ export const INBOUND_JOB = "inbound";
|
|
|
40
40
|
* 用户发来的消息不能排在它们后面。
|
|
41
41
|
*/
|
|
42
42
|
export const INBOUND_PRIORITY = 1;
|
|
43
|
-
export const DELIVER_PRIORITY =
|
|
43
|
+
export const DELIVER_PRIORITY = OUTBOX_JOBS.deliver.opts.priority;
|
|
44
44
|
/** 入站任务的总尝试次数(处理失败由 BullMQ 指数退避重试:1s、2s、4s、8s)。 */
|
|
45
45
|
export const INBOUND_ATTEMPTS = 5;
|
|
46
46
|
const INBOUND_BACKOFF_MS = 1000;
|
|
@@ -53,30 +53,31 @@ export const inboundJobId = (connectionId, messageId) => `inbound-${connectionId
|
|
|
53
53
|
* The producer side of the channel queue `cap-kernel-channels` (any role): delivery jobs for a
|
|
54
54
|
* conversation with an IM target, inbound jobs (Ruling A21), and the catch-up of a connection that
|
|
55
55
|
* can deliver again. Its consumer is {@link ChannelOutbound} through the `@Processor` of the worker
|
|
56
|
-
* role.
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
56
|
+
* role. A delivery is owed (transactional outbox spec §8.1): every event append of a conversation
|
|
57
|
+
* with a channel target adds its deliver job to the outbox in the append's transaction (a reply, an
|
|
58
|
+
* approval decision, a question answer, a wait stop all append), and {@link bind} owes the first
|
|
59
|
+
* one with the target. The direct {@link enqueue} is left for hints and catch-ups: a run starting
|
|
60
|
+
* here (`run.started`, so its streaming drafts start at once), a finished delivery job's re-check,
|
|
61
|
+
* a card click's thread and a connection that can deliver again.
|
|
60
62
|
*/
|
|
61
63
|
let ChannelJobs = class ChannelJobs {
|
|
62
64
|
db;
|
|
63
65
|
queue;
|
|
64
66
|
log;
|
|
67
|
+
outbox;
|
|
68
|
+
txHost;
|
|
65
69
|
/** Stopped (the stop's channel-outbound phase): enqueues do nothing, inbound enqueues throw. */
|
|
66
70
|
closed = false;
|
|
67
71
|
unsubscribe;
|
|
68
|
-
constructor(db, queue, events, log) {
|
|
72
|
+
constructor(db, queue, events, log, outbox, txHost) {
|
|
69
73
|
this.db = db;
|
|
70
74
|
this.queue = queue;
|
|
71
75
|
this.log = log;
|
|
76
|
+
this.outbox = outbox;
|
|
77
|
+
this.txHost = txHost;
|
|
72
78
|
queue.on("error", (err) => this.log.error("channel outbound queue error", { err }));
|
|
73
|
-
const soon = ({ conversationId }) => this.enqueueSoon(conversationId);
|
|
74
79
|
this.unsubscribe = [
|
|
75
|
-
events.on("
|
|
76
|
-
events.on("run.started", soon),
|
|
77
|
-
events.on("run.wait-stopped", soon),
|
|
78
|
-
events.on("approval.decided", soon),
|
|
79
|
-
events.on("question.answered", soon),
|
|
80
|
+
events.on("run.started", ({ conversationId }) => this.enqueueSoon(conversationId)),
|
|
80
81
|
];
|
|
81
82
|
}
|
|
82
83
|
/** Unsubscribes after the stop phases: events emitted while they drain are still handled. */
|
|
@@ -84,11 +85,46 @@ let ChannelJobs = class ChannelJobs {
|
|
|
84
85
|
for (const off of this.unsubscribe)
|
|
85
86
|
off();
|
|
86
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Makes `target` (on `connectionId`) the conversation's delivery target and owes its delivery
|
|
90
|
+
* from the current log position, in one transaction. A new target starts delivering after
|
|
91
|
+
* `seq` (the message that bound it); a known one keeps its progress. The conversation row is
|
|
92
|
+
* locked first, as an append locks it: an append either committed before (its events are below
|
|
93
|
+
* the owed position) or reads the target (and owes its own job).
|
|
94
|
+
*/
|
|
95
|
+
async bind(orgId, conversationId, connectionId, target, seq) {
|
|
96
|
+
const conv = await this.db
|
|
97
|
+
.selectFrom("conversations")
|
|
98
|
+
.select("last_seq")
|
|
99
|
+
.where("id", "=", conversationId)
|
|
100
|
+
.forUpdate()
|
|
101
|
+
.executeTakeFirst();
|
|
102
|
+
if (!conv)
|
|
103
|
+
return;
|
|
104
|
+
await this.db
|
|
105
|
+
.insertInto("channel_deliveries")
|
|
106
|
+
.values({
|
|
107
|
+
conversation_id: conversationId,
|
|
108
|
+
connection_id: connectionId,
|
|
109
|
+
target: JSON.stringify(target),
|
|
110
|
+
last_seq: seq,
|
|
111
|
+
})
|
|
112
|
+
.onConflict((oc) => oc.column("conversation_id").doUpdateSet({
|
|
113
|
+
connection_id: connectionId,
|
|
114
|
+
target: JSON.stringify(target),
|
|
115
|
+
updated_at: new Date(),
|
|
116
|
+
}))
|
|
117
|
+
.execute();
|
|
118
|
+
await oweDelivery(this.outbox, { conversationId, orgId, seq: Number(conv.last_seq) });
|
|
119
|
+
}
|
|
87
120
|
/** 会话有 IM 投递目标时排一个出站任务,不等入队完成;失败只记日志。 */
|
|
88
121
|
enqueueSoon(conversationId) {
|
|
89
122
|
this.enqueue(conversationId).catch((err) => this.log.warn("cannot enqueue channel delivery", { conversationId, err }));
|
|
90
123
|
}
|
|
91
|
-
/**
|
|
124
|
+
/**
|
|
125
|
+
* A hint (not owed work, see the class): a delivery job for a conversation with an IM target (one
|
|
126
|
+
* per log position; `followUp` gets a fresh id); does nothing once closed.
|
|
127
|
+
*/
|
|
92
128
|
async enqueue(conversationId, opts = {}) {
|
|
93
129
|
if (this.closed)
|
|
94
130
|
return;
|
|
@@ -101,14 +137,10 @@ let ChannelJobs = class ChannelJobs {
|
|
|
101
137
|
if (!row || this.closed)
|
|
102
138
|
return;
|
|
103
139
|
await this.queue.add(DELIVER_JOB, { conversationId }, {
|
|
140
|
+
...OUTBOX_JOBS.deliver.opts,
|
|
104
141
|
jobId: opts.followUp
|
|
105
142
|
? followUpJobId(conversationId, Number(row.last_seq))
|
|
106
143
|
: deliverJobId(conversationId, Number(row.last_seq)),
|
|
107
|
-
attempts: DELIVER_ATTEMPTS,
|
|
108
|
-
backoff: { type: "deliver" },
|
|
109
|
-
priority: DELIVER_PRIORITY,
|
|
110
|
-
removeOnComplete: true,
|
|
111
|
-
removeOnFail: true,
|
|
112
144
|
});
|
|
113
145
|
}
|
|
114
146
|
/**
|
|
@@ -147,11 +179,16 @@ let ChannelJobs = class ChannelJobs {
|
|
|
147
179
|
this.closed = true;
|
|
148
180
|
}
|
|
149
181
|
};
|
|
182
|
+
__decorate([
|
|
183
|
+
Transactional()
|
|
184
|
+
], ChannelJobs.prototype, "bind", null);
|
|
150
185
|
ChannelJobs = __decorate([
|
|
151
186
|
Injectable(),
|
|
152
187
|
__param(0, Inject(KernelDb)),
|
|
153
188
|
__param(1, Inject(getQueueToken(CHANNEL_QUEUE_NAME))),
|
|
154
189
|
__param(2, Inject(KernelEvents)),
|
|
155
|
-
__param(3, Inject(KERNEL_LOGGER))
|
|
190
|
+
__param(3, Inject(KERNEL_LOGGER)),
|
|
191
|
+
__param(4, Inject(OutboxService)),
|
|
192
|
+
__param(5, Inject(TransactionHost))
|
|
156
193
|
], ChannelJobs);
|
|
157
194
|
export { ChannelJobs };
|
|
@@ -21,9 +21,10 @@ export declare class AnonymousGuests {
|
|
|
21
21
|
readonly txHost: TransactionHost;
|
|
22
22
|
constructor(db: KernelDb, guestLock: AnonymousGuestLock, txHost: TransactionHost);
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
24
|
+
* The org's one anonymous guest account id, created on first use (`accounts.status = active`, no
|
|
25
|
+
* way to sign in, org role guest). Every call makes sure the membership exists (a removed guest
|
|
26
|
+
* is added back on its next use). Concurrent first creations across replicas are serialized by
|
|
27
|
+
* {@link AnonymousGuestLock}: one account.
|
|
27
28
|
*/
|
|
28
29
|
ensure(orgId: string): Promise<string>;
|
|
29
30
|
}
|
package/dist/channels/threads.js
CHANGED
|
@@ -55,9 +55,10 @@ let AnonymousGuests = class AnonymousGuests {
|
|
|
55
55
|
this.txHost = txHost;
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
58
|
+
* The org's one anonymous guest account id, created on first use (`accounts.status = active`, no
|
|
59
|
+
* way to sign in, org role guest). Every call makes sure the membership exists (a removed guest
|
|
60
|
+
* is added back on its next use). Concurrent first creations across replicas are serialized by
|
|
61
|
+
* {@link AnonymousGuestLock}: one account.
|
|
61
62
|
*/
|
|
62
63
|
async ensure(orgId) {
|
|
63
64
|
await this.guestLock.lock(orgId);
|
package/dist/config/schema.d.ts
CHANGED
|
@@ -11,8 +11,6 @@ export interface FieldMeta {
|
|
|
11
11
|
* 用法:`z.string().meta(meta({ secret: true, description: "..." }))`。
|
|
12
12
|
*/
|
|
13
13
|
export declare function meta(opts: FieldMeta): FieldMeta;
|
|
14
|
-
/** `runtime.maxRunSeconds` 的默认值。 */
|
|
15
|
-
export declare const DEFAULT_MAX_RUN_SECONDS = 900;
|
|
16
14
|
/** `sandbox.limits.maxCommandSeconds` 的默认值。 */
|
|
17
15
|
export declare const DEFAULT_MAX_COMMAND_SECONDS = 7200;
|
|
18
16
|
/** access token 寿命上限(秒);会话吊销标记的 TTL 按它计算,与实例当前配置无关。 */
|
|
@@ -268,7 +266,6 @@ export declare const KernelConfigSchema: z.ZodObject<{
|
|
|
268
266
|
hooks: z.ZodPrefault<z.ZodObject<{
|
|
269
267
|
timeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
270
268
|
usageReportConcurrency: z.ZodDefault<z.ZodNumber>;
|
|
271
|
-
usageReportKeepHours: z.ZodDefault<z.ZodNumber>;
|
|
272
269
|
}, z.core.$strip>>;
|
|
273
270
|
log: z.ZodPrefault<z.ZodObject<{
|
|
274
271
|
level: z.ZodDefault<z.ZodEnum<{
|
package/dist/config/schema.js
CHANGED
|
@@ -22,8 +22,6 @@ function isValidMasterKey(value) {
|
|
|
22
22
|
* 插件名同清单规则(不能是 `local`),租户 id 非空、不含空白;与 identity/external.ts 的身份源键规则一致。
|
|
23
23
|
*/
|
|
24
24
|
const TRUSTED_SOURCE_RE = /^(?!local:)[a-z0-9][a-z0-9._-]{0,213}:\S{1,256}$/;
|
|
25
|
-
/** `runtime.maxRunSeconds` 的默认值。 */
|
|
26
|
-
export const DEFAULT_MAX_RUN_SECONDS = 900;
|
|
27
25
|
/** `sandbox.limits.maxCommandSeconds` 的默认值。 */
|
|
28
26
|
export const DEFAULT_MAX_COMMAND_SECONDS = 7200;
|
|
29
27
|
/** access token 寿命上限(秒);会话吊销标记的 TTL 按它计算,与实例当前配置无关。 */
|
|
@@ -573,9 +571,11 @@ export const KernelConfigSchema = z.object({
|
|
|
573
571
|
maxSteps: z
|
|
574
572
|
.number()
|
|
575
573
|
.int()
|
|
576
|
-
.
|
|
577
|
-
.default(
|
|
578
|
-
.meta(meta({
|
|
574
|
+
.nonnegative()
|
|
575
|
+
.default(0)
|
|
576
|
+
.meta(meta({
|
|
577
|
+
description: "Maximum model steps per agent run before the final wrap-up; 0 (the default) means no limit: a run goes on until the model stops calling tools or someone stops it",
|
|
578
|
+
})),
|
|
579
579
|
wakeOnBackgroundTask: z
|
|
580
580
|
.boolean()
|
|
581
581
|
.default(true)
|
|
@@ -585,10 +585,10 @@ export const KernelConfigSchema = z.object({
|
|
|
585
585
|
maxRunSeconds: z
|
|
586
586
|
.number()
|
|
587
587
|
.int()
|
|
588
|
-
.
|
|
589
|
-
.default(
|
|
588
|
+
.nonnegative()
|
|
589
|
+
.default(0)
|
|
590
590
|
.meta(meta({
|
|
591
|
-
description: "Maximum wall-clock duration of one agent run in seconds (time spent waiting for people is not counted).
|
|
591
|
+
description: "Maximum wall-clock duration of one agent run in seconds (time spent waiting for people is not counted); 0 (the default) means no limit. With a limit, sandbox commands are limited to the time left in the run, so agents that need long commands need maxRunSeconds >= sandbox.limits.maxCommandSeconds; without one, commands are limited only by sandbox.limits.maxCommandSeconds and the tool timeouts",
|
|
592
592
|
})),
|
|
593
593
|
streamIdleMs: z
|
|
594
594
|
.number()
|
|
@@ -669,9 +669,9 @@ export const KernelConfigSchema = z.object({
|
|
|
669
669
|
})),
|
|
670
670
|
})
|
|
671
671
|
.default({
|
|
672
|
-
maxSteps:
|
|
672
|
+
maxSteps: 0,
|
|
673
673
|
wakeOnBackgroundTask: true,
|
|
674
|
-
maxRunSeconds:
|
|
674
|
+
maxRunSeconds: 0,
|
|
675
675
|
streamIdleMs: 60000,
|
|
676
676
|
maxOutputTokens: 16000,
|
|
677
677
|
compactionThreshold: 0.8,
|
|
@@ -1178,7 +1178,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1178
1178
|
.positive()
|
|
1179
1179
|
.default(DEFAULT_MAX_COMMAND_SECONDS)
|
|
1180
1180
|
.meta(meta({
|
|
1181
|
-
description: "Longest a single sandbox command may run, in seconds.
|
|
1181
|
+
description: "Longest a single sandbox command may run, in seconds. When runtime.maxRunSeconds is set (not 0), a command also stops when its run is about to reach it, so long commands need runtime.maxRunSeconds >= maxCommandSeconds (a startup warning is logged otherwise)",
|
|
1182
1182
|
})),
|
|
1183
1183
|
suspendAfterIdleMinutes: z
|
|
1184
1184
|
.number()
|
|
@@ -1443,15 +1443,6 @@ export const KernelConfigSchema = z.object({
|
|
|
1443
1443
|
.meta(meta({
|
|
1444
1444
|
description: "usage.report delivery jobs one worker replica processes at the same time",
|
|
1445
1445
|
})),
|
|
1446
|
-
usageReportKeepHours: z
|
|
1447
|
-
.number()
|
|
1448
|
-
.int()
|
|
1449
|
-
.min(1)
|
|
1450
|
-
.max(720)
|
|
1451
|
-
.default(24)
|
|
1452
|
-
.meta(meta({
|
|
1453
|
-
description: "Hours a finished usage.report job is kept in Redis so re-enqueueing the same usage event (resumed step, sweeper) is deduplicated; at least 1, well above the sweeper's 10-minute overlap",
|
|
1454
|
-
})),
|
|
1455
1446
|
})
|
|
1456
1447
|
.prefault({}),
|
|
1457
1448
|
log: z
|
|
@@ -44,3 +44,19 @@ export interface AgentTreeNode {
|
|
|
44
44
|
* check of the root.
|
|
45
45
|
*/
|
|
46
46
|
export declare function readAgentTree(db: KernelSchemaDb, orgId: string, rootId: string): Promise<AgentTreeNode | null>;
|
|
47
|
+
/** One sub-agent a conversation dispatched, as `TaskList` lists it. */
|
|
48
|
+
export interface ChildAgent {
|
|
49
|
+
/** The child conversation's id: the agentId the parent saw. */
|
|
50
|
+
id: string;
|
|
51
|
+
/** The dispatched description (the child's title when no dispatch event has one). */
|
|
52
|
+
description: string;
|
|
53
|
+
/** The latest run's status; `queued` before the first run is recorded. */
|
|
54
|
+
status: "queued" | "running" | "waiting" | "completed" | "failed" | "aborted";
|
|
55
|
+
/** When the latest run ended; null while it is active. */
|
|
56
|
+
finishedAt: Date | null;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The sub-agents `parentId` of org `orgId` dispatched itself (not their own sub-agents), oldest
|
|
60
|
+
* first: live sub-agent conversations with a dispatch row, as {@link readAgentTree} counts them.
|
|
61
|
+
*/
|
|
62
|
+
export declare function readChildAgents(db: KernelSchemaDb, orgId: string, parentId: string): Promise<ChildAgent[]>;
|
|
@@ -90,3 +90,39 @@ function toNode(r, isRoot) {
|
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
92
|
const modelOf = (m) => m ? { provider: m.provider, model: m.model } : null;
|
|
93
|
+
/**
|
|
94
|
+
* The sub-agents `parentId` of org `orgId` dispatched itself (not their own sub-agents), oldest
|
|
95
|
+
* first: live sub-agent conversations with a dispatch row, as {@link readAgentTree} counts them.
|
|
96
|
+
*/
|
|
97
|
+
export async function readChildAgents(db, orgId, parentId) {
|
|
98
|
+
const { rows } = await sql `
|
|
99
|
+
SELECT c.id, c.title,
|
|
100
|
+
(SELECT e.payload->>'description' FROM capybara.conversation_events e
|
|
101
|
+
WHERE e.conversation_id = c.parent_conversation_id AND e.type = 'subagent_dispatched'
|
|
102
|
+
AND e.payload->>'subagentId' = c.id
|
|
103
|
+
ORDER BY e.seq DESC LIMIT 1) AS description,
|
|
104
|
+
latest.status AS last_status, latest.finished_at AS last_finished_at
|
|
105
|
+
FROM capybara.conversations c
|
|
106
|
+
LEFT JOIN LATERAL (
|
|
107
|
+
SELECT r.status, r.finished_at FROM capybara.runs r
|
|
108
|
+
WHERE r.conversation_id = c.id
|
|
109
|
+
ORDER BY r.created_at DESC, r.id DESC
|
|
110
|
+
LIMIT 1
|
|
111
|
+
) latest ON true
|
|
112
|
+
WHERE c.parent_conversation_id = ${parentId} AND c.org_id = ${orgId}
|
|
113
|
+
AND c.kind = 'subagent' AND c.deleted_at IS NULL
|
|
114
|
+
AND EXISTS (
|
|
115
|
+
SELECT 1 FROM capybara.subagent_dispatches sd WHERE sd.child_conversation_id = c.id
|
|
116
|
+
)
|
|
117
|
+
ORDER BY c.created_at, c.id
|
|
118
|
+
`.execute(db);
|
|
119
|
+
return rows.map((r) => {
|
|
120
|
+
const status = r.last_status ?? "queued";
|
|
121
|
+
return {
|
|
122
|
+
id: r.id,
|
|
123
|
+
description: r.description ?? r.title ?? "",
|
|
124
|
+
status,
|
|
125
|
+
finishedAt: ACTIVE.has(status) ? null : (r.last_finished_at ?? null),
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
}
|
|
@@ -190,7 +190,9 @@ let ConversationsController = class ConversationsController {
|
|
|
190
190
|
const pick = body.deviceId === undefined ? {} : { deviceId: body.deviceId };
|
|
191
191
|
if (body.message === undefined) {
|
|
192
192
|
return {
|
|
193
|
-
conversation: await this.conversations.create(org.orgId, p.account.id, body.agentId, pick
|
|
193
|
+
conversation: await this.conversations.create(org.orgId, p.account.id, body.agentId, pick, {
|
|
194
|
+
source: "web",
|
|
195
|
+
}),
|
|
194
196
|
};
|
|
195
197
|
}
|
|
196
198
|
const m = body.message;
|
|
@@ -204,7 +206,7 @@ let ConversationsController = class ConversationsController {
|
|
|
204
206
|
...(m.skill !== undefined && { skill: m.skill }),
|
|
205
207
|
...(m.timeZone !== undefined && { timeZone: m.timeZone }),
|
|
206
208
|
...(m.locale !== undefined && { locale: m.locale }),
|
|
207
|
-
}, pick);
|
|
209
|
+
}, pick, { source: "web" });
|
|
208
210
|
reply.status(out.created ? 201 : 200);
|
|
209
211
|
return { conversation: out.conversation, event: out.event, events: out.events };
|
|
210
212
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ConversationSource } from "@capybara-hq/plugin-sdk";
|
|
1
2
|
import { AgentLookup } from "../agents/agent-lookup.js";
|
|
2
3
|
import type { ModelRef } from "../agents/definition.js";
|
|
3
4
|
import type { AgentAvatar } from "../agents/profile.js";
|
|
@@ -7,7 +8,6 @@ import { ConversationDevices, type NewConversationDevice } from "../devices/conv
|
|
|
7
8
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
8
9
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
9
10
|
import { KernelEvents } from "../infra/events/kernel-events.js";
|
|
10
|
-
import type { KernelLogger } from "../log.js";
|
|
11
11
|
import { ProviderRegistry } from "../runtime/providers.js";
|
|
12
12
|
import type { ScheduleMarker } from "../schedules/types.js";
|
|
13
13
|
import { type RenderedInvocation, SkillInvoker } from "../skills/invoke.js";
|
|
@@ -118,15 +118,37 @@ export interface ReplySkips {
|
|
|
118
118
|
export declare const NO_REPLY_SKIPS: ReplySkips;
|
|
119
119
|
/** 会话服务用到的运行控制:投递运行(RunQueue)与跨副本中止(RunAbort)。 */
|
|
120
120
|
export interface RunControl {
|
|
121
|
-
/**
|
|
122
|
-
|
|
121
|
+
/**
|
|
122
|
+
* The direct `ensureRun` after a commit that owes the ensure-run backstop: a failure is logged,
|
|
123
|
+
* never thrown (transactional outbox spec §6).
|
|
124
|
+
*/
|
|
125
|
+
ensureRunAfterCommit(conversationId: string): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Owes the ensure-run backstop in the caller's transaction (transactional outbox spec §6): `seq`
|
|
128
|
+
* is the event it wrote (or the conversation's newest), `orgId` the conversation's.
|
|
129
|
+
*/
|
|
130
|
+
oweEnsureRun(conversationId: string, seq: number | string, orgId: string): Promise<boolean>;
|
|
123
131
|
/** After a root's queue was unpaused: the wakes it held for its tree (agent map spec §5.3). */
|
|
124
132
|
wakeHeldTree(rootId: string): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* In the transaction that may release a root's hold: owes the ensure-run backstop of each
|
|
135
|
+
* sub-agent {@link wakeHeldTree} wakes after the commit (transactional outbox spec §6).
|
|
136
|
+
*/
|
|
137
|
+
oweHeldTreeIn(rootId: string): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* In a decision's transaction, after its decided rows: resumes the waiting run when it waits on
|
|
140
|
+
* nothing else (lock order: conversations, decided rows, runs).
|
|
141
|
+
*/
|
|
142
|
+
resumeIn(runId: string, waitId: string): Promise<unknown>;
|
|
143
|
+
/** In a root's delete transaction: owes the stop of its sub-agent tree (`stop-tree`). */
|
|
144
|
+
oweStopDeletedTree(conversationId: string, byAccountId: string | null, orgId: string): Promise<boolean>;
|
|
125
145
|
/**
|
|
126
146
|
* 运行是孤儿(会话锁空闲、任务已不存在,没有 worker 会收到中止广播)时直接把它写成 aborted,返回 true;
|
|
127
147
|
* 否则返回 false。
|
|
128
148
|
*/
|
|
129
149
|
abortIfOrphaned(conversationId: string, runId: string, byAccountId: string): Promise<boolean>;
|
|
150
|
+
/** Ends a run still `queued` in PG before a worker started it (`RunQueue.abortQueued`): true. */
|
|
151
|
+
abortQueued(conversationId: string, runId: string, byAccountId: string): Promise<boolean>;
|
|
130
152
|
/**
|
|
131
153
|
* 运行在等人处理(waiting)时直接中止:取消等待、写 `run_aborted`、删除 checkpoint,返回 true;
|
|
132
154
|
* 运行已不是 waiting(例如刚被续跑)→ false。
|
|
@@ -209,6 +231,14 @@ export interface InternalMessageOptions {
|
|
|
209
231
|
schedule?: ScheduleMarker;
|
|
210
232
|
timeZoneOverride?: string;
|
|
211
233
|
}
|
|
234
|
+
/** Options of a conversation created by a kernel caller (never an HTTP body). */
|
|
235
|
+
export interface NewConversationOptions {
|
|
236
|
+
/**
|
|
237
|
+
* Where it comes from (memory plugin spec §6.2), fixed at creation. Required: a channel or group
|
|
238
|
+
* conversation that fell back to `web` would be offered what only the web and DMs may see.
|
|
239
|
+
*/
|
|
240
|
+
source: ConversationSource;
|
|
241
|
+
}
|
|
212
242
|
/**
|
|
213
243
|
* 会话:只有所有者可见;每次访问都实时复核 agent 对所有者仍可用(spec 3.6 R5),
|
|
214
244
|
* 不可用时会话也按不存在处理(`conversation.not_found`)。
|
|
@@ -222,7 +252,6 @@ export declare class ConversationsService {
|
|
|
222
252
|
private readonly runs;
|
|
223
253
|
/** Resolves a switched-to model and its declared parameters (UI refresh B). */
|
|
224
254
|
private readonly providers;
|
|
225
|
-
private readonly log;
|
|
226
255
|
/** Reads `@` resources with the sender's credentials. */
|
|
227
256
|
private readonly content;
|
|
228
257
|
/** Binds uploaded files to the conversation in the message's transaction. */
|
|
@@ -243,7 +272,7 @@ export declare class ConversationsService {
|
|
|
243
272
|
/** Starts and stops the conversation's runs. */
|
|
244
273
|
runs: RunControl,
|
|
245
274
|
/** Resolves a switched-to model and its declared parameters (UI refresh B). */
|
|
246
|
-
providers: Pick<ProviderRegistry, "resolve">,
|
|
275
|
+
providers: Pick<ProviderRegistry, "resolve">,
|
|
247
276
|
/** Reads `@` resources with the sender's credentials. */
|
|
248
277
|
content: Pick<ConnectorContent, "resolveAttachments">,
|
|
249
278
|
/** Binds uploaded files to the conversation in the message's transaction. */
|
|
@@ -258,18 +287,14 @@ export declare class ConversationsService {
|
|
|
258
287
|
questions: Pick<QuestionsService, "skipPendingIn">,
|
|
259
288
|
/** ... and its pending network asks (network ask-to-allow spec §6.7). */
|
|
260
289
|
approvals: Pick<ApprovalsService, "skipNetworkIn">, events: Pick<KernelEvents, "emit">, txHost: TransactionHost);
|
|
261
|
-
/**
|
|
262
|
-
* 不阻塞地调用一次 `ensureRun`(打开 SSE、读事件时):它幂等,并顺带清理孤儿运行,
|
|
263
|
-
* 会话不会因为某次运行结束后的投递失败而永远停在「运行中」。失败只记日志。
|
|
264
|
-
*/
|
|
265
|
-
kickRun(conversationId: string): void;
|
|
266
290
|
/**
|
|
267
291
|
* Creates an empty conversation bound to its device (`pick`, see
|
|
268
292
|
* {@link ConversationDevices.forNew}); an agent the account cannot use →
|
|
269
293
|
* `agent.not_found`, a device it may not use → `device.not_found` /
|
|
270
|
-
* `device.unavailable`, and nothing is created.
|
|
294
|
+
* `device.unavailable`, and nothing is created. `opts.source` records where the conversation
|
|
295
|
+
* comes from.
|
|
271
296
|
*/
|
|
272
|
-
create(orgId: string, accountId: string, agentId: string, pick
|
|
297
|
+
create(orgId: string, accountId: string, agentId: string, pick: NewConversationDevice | undefined, opts: NewConversationOptions): Promise<ConversationView>;
|
|
273
298
|
/**
|
|
274
299
|
* Creates a conversation together with its first message (UI refresh B, create on first send):
|
|
275
300
|
* the conversation row and the `user_message` are written in one transaction, keyed by the
|
|
@@ -278,12 +303,12 @@ export declare class ConversationsService {
|
|
|
278
303
|
* `agent.not_found` and nothing is written. Queues a run afterwards, like `postUserMessage`.
|
|
279
304
|
* `events` are every event the create wrote, in seq order from seq 1 (a `model_switched` before
|
|
280
305
|
* the message when the send switched), so a client can seed the new conversation's log whole.
|
|
281
|
-
* `internal
|
|
282
|
-
* `conversations.scheduled_task_id`, and its zone override.
|
|
306
|
+
* `internal`: the conversation's source and, for kernel callers only, a scheduled task's marker,
|
|
307
|
+
* which also sets `conversations.scheduled_task_id`, and its zone override.
|
|
283
308
|
*/
|
|
284
309
|
createWithMessage(orgId: string, accountId: string, agentId: string, input: UserMessageInput & {
|
|
285
310
|
clientMessageId: string;
|
|
286
|
-
}, pick
|
|
311
|
+
}, pick: NewConversationDevice | undefined, internal: InternalMessageOptions & NewConversationOptions): Promise<{
|
|
287
312
|
conversation: ConversationView;
|
|
288
313
|
event: ConversationEvent;
|
|
289
314
|
events: ConversationEvent[];
|
|
@@ -297,6 +322,11 @@ export declare class ConversationsService {
|
|
|
297
322
|
* the other conversation is never returned).
|
|
298
323
|
*/
|
|
299
324
|
private findCreated;
|
|
325
|
+
/**
|
|
326
|
+
* The direct `ensureRun` after a message's commit ({@link RunControl.ensureRunAfterCommit}): a
|
|
327
|
+
* failure never fails the request, since the message's transaction owes the ensure-run backstop.
|
|
328
|
+
*/
|
|
329
|
+
private startRun;
|
|
300
330
|
private rowView;
|
|
301
331
|
/**
|
|
302
332
|
* Renames a conversation (owner only, as {@link get}): `title_source = 'manual'`, so the title
|
|
@@ -399,12 +429,15 @@ export declare class ConversationsService {
|
|
|
399
429
|
* only after an access check.
|
|
400
430
|
*/
|
|
401
431
|
sandboxConversationOf(orgId: string, conversationId: string): Promise<string>;
|
|
402
|
-
/**
|
|
432
|
+
/**
|
|
433
|
+
* 读事件(先做 `get` 的可见性判定). A read never changes run state (transactional outbox spec
|
|
434
|
+
* §6): a run nobody runs is the `run-orphan-check`'s to repair.
|
|
435
|
+
*/
|
|
403
436
|
listEvents(orgId: string, conversationId: string, viewerAccountId: string, afterSeq: number, limit: number): Promise<ConversationEvent[]>;
|
|
404
437
|
/**
|
|
405
438
|
* The turn-aligned page of events before `beforeSeq` (`null`: the log's last page), with how
|
|
406
439
|
* many runs started before it ({@link EventLog.readTurnPageBefore}; history paging spec §2).
|
|
407
|
-
* Visibility as {@link get};
|
|
440
|
+
* Visibility as {@link get}; a read only, as {@link listEvents}.
|
|
408
441
|
*/
|
|
409
442
|
listEventsBefore(orgId: string, conversationId: string, viewerAccountId: string, beforeSeq: number | null, limit: number): Promise<{
|
|
410
443
|
events: ConversationEvent[];
|
|
@@ -413,7 +446,8 @@ export declare class ConversationsService {
|
|
|
413
446
|
/**
|
|
414
447
|
* 追加一条用户消息;带 `clientMessageId` 时重复提交返回同一事件。写入后调用 `ensureRun`:
|
|
415
448
|
* 没有进行中的运行时投递一轮;运行中则由当前运行在步骤间隙吸收,或在它结束时再次 `ensureRun`。
|
|
416
|
-
*
|
|
449
|
+
* A failed `ensureRun` is logged, not thrown: the message's transaction owes the ensure-run
|
|
450
|
+
* backstop, which starts the run once the queue is reachable (transactional outbox spec §6).
|
|
417
451
|
*
|
|
418
452
|
* `attachments`(`@` 资源引用):内核以发送者的凭据读取资源(打码、限长),作为用户文本之后的额外文本块写入同一条
|
|
419
453
|
* user_message,并在 `payload.attachments` 记录元数据(第 i 个附件对应 `content[i + 1]`)。读取失败整条不写。
|
|
@@ -452,6 +486,13 @@ export declare class ConversationsService {
|
|
|
452
486
|
* conversations (network ask-to-allow spec §6.7). The queue's "send now" uses it as the direct
|
|
453
487
|
* send does; announce after the commit with {@link announceSkipped}. `toSeq` is the highest seq
|
|
454
488
|
* written in this conversation (null: none).
|
|
489
|
+
*
|
|
490
|
+
* Lock order: this (root) conversation (the caller's), its pending questions, the sub-agents'
|
|
491
|
+
* conversations with a pending network ask (id order), the asks themselves (the root's and the
|
|
492
|
+
* sub-agents'), and only then the run rows, as each skipped wait's run resumes in this
|
|
493
|
+
* transaction. Every run row comes after every conversation and decided row (ruling R19); a
|
|
494
|
+
* sub-agent's conversation comes after the root's questions, which only this path locks with a
|
|
495
|
+
* sub-agent conversation after them.
|
|
455
496
|
*/
|
|
456
497
|
skipWaitsIn(conversationId: string, accountId: string, messageSeq: number): Promise<{
|
|
457
498
|
skipped: ReplySkips;
|
|
@@ -460,7 +501,8 @@ export declare class ConversationsService {
|
|
|
460
501
|
/**
|
|
461
502
|
* After the commit: announces each skipped question (`question.answered`, outcome `skipped`) and
|
|
462
503
|
* network ask (`approval.decided`, status `skipped`; a sub-agent's conversation is notified
|
|
463
|
-
* first)
|
|
504
|
+
* first) as domain events with no kernel subscriber: the IM card updates are owed by the skips'
|
|
505
|
+
* appends (transactional outbox spec §8.1); the run resumed in the message's transaction.
|
|
464
506
|
*/
|
|
465
507
|
announceSkipped(skipped: ReplySkips): Promise<void>;
|
|
466
508
|
/**
|