@capybara-hq/kernel 0.1.0-rc.135 → 0.1.0-rc.136
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/admin/admin.module.js +3 -0
- package/dist/admin/health.service.d.ts +2 -2
- package/dist/admin/health.service.js +6 -2
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/conversations/access.d.ts +15 -7
- package/dist/conversations/access.js +59 -10
- package/dist/conversations/conversation-agent.d.ts +18 -0
- package/dist/conversations/conversation-agent.js +23 -0
- package/dist/conversations/conversation-ref.d.ts +3 -2
- package/dist/conversations/conversation-ref.js +6 -1
- package/dist/conversations/conversations.controller.d.ts +28 -5
- package/dist/conversations/conversations.controller.js +99 -10
- package/dist/conversations/conversations.module.js +10 -0
- package/dist/conversations/conversations.schemas.d.ts +6 -0
- package/dist/conversations/conversations.schemas.js +15 -0
- package/dist/conversations/conversations.service.d.ts +125 -21
- package/dist/conversations/conversations.service.js +260 -90
- package/dist/conversations/event-log.d.ts +9 -1
- package/dist/conversations/event-log.js +2 -0
- package/dist/conversations/events.d.ts +57 -0
- package/dist/conversations/events.js +73 -1
- package/dist/conversations/external/external-calls.d.ts +75 -0
- package/dist/conversations/external/external-calls.js +91 -0
- package/dist/conversations/external/external-calls.processor.d.ts +45 -0
- package/dist/conversations/external/external-calls.processor.js +144 -0
- package/dist/conversations/external/external-conversations.service.d.ts +266 -0
- package/dist/conversations/external/external-conversations.service.js +1138 -0
- package/dist/conversations/external/external.schemas.d.ts +63 -0
- package/dist/conversations/external/external.schemas.js +52 -0
- package/dist/conversations/external/token.d.ts +6 -0
- package/dist/conversations/external/token.js +6 -0
- package/dist/conversations/permission-profile-store.d.ts +4 -1
- package/dist/conversations/permission-profiles.controller.d.ts +33 -9
- package/dist/conversations/permission-profiles.controller.js +86 -6
- package/dist/conversations/prompt-suggestions.js +2 -1
- package/dist/conversations/queue.js +2 -1
- package/dist/conversations/titles.js +4 -3
- package/dist/ctx/create-ctx.d.ts +7 -0
- package/dist/ctx/create-ctx.js +45 -2
- package/dist/db/kernel-schema.d.ts +31 -4
- package/dist/device-access/host-services.js +3 -2
- package/dist/device-access/person-handles.d.ts +16 -7
- package/dist/device-access/person-handles.js +14 -9
- package/dist/devices/conversation-devices.d.ts +5 -0
- package/dist/devices/conversation-devices.js +16 -0
- package/dist/erasure/org-catalog.js +2 -2
- package/dist/errors.d.ts +34 -0
- package/dist/errors.js +34 -0
- package/dist/evals/snapshot.js +3 -1
- package/dist/evals/trajectory.service.d.ts +2 -2
- package/dist/evals/trajectory.service.js +11 -7
- package/dist/extensions/extensions.module.js +3 -0
- package/dist/extensions/host.d.ts +7 -0
- package/dist/extensions/host.js +11 -0
- package/dist/extensions/permission-view.d.ts +3 -1
- package/dist/extensions/permission-view.js +4 -1
- package/dist/extensions/point-defaults.d.ts +13 -21
- package/dist/extensions/point-defaults.js +32 -72
- package/dist/extensions/point-serving.d.ts +56 -0
- package/dist/extensions/point-serving.js +120 -0
- package/dist/inbox/inbox-items.service.d.ts +11 -0
- package/dist/inbox/inbox-items.service.js +39 -0
- package/dist/infra/outbox/registry.d.ts +70 -0
- package/dist/infra/outbox/registry.js +44 -0
- package/dist/infra/queue/queue-names.d.ts +1 -1
- package/dist/infra/queue/queue-names.js +1 -0
- package/dist/kernel.module.js +4 -0
- package/dist/platform/exclusions.js +10 -0
- package/dist/platform/ops/conversations.ops.d.ts +8 -1
- package/dist/platform/ops/conversations.ops.js +52 -14
- package/dist/plugin-reads/plugin-reads.service.js +4 -1
- package/dist/push/recipients.js +5 -2
- package/dist/retention/worker.js +2 -1
- package/dist/roles/worker-role.d.ts +3 -1
- package/dist/roles/worker-role.js +8 -2
- package/dist/roles/worker.module.js +3 -0
- package/dist/runtime/context/build.js +8 -0
- package/dist/runtime/context/compaction.js +7 -0
- package/dist/runtime/idle-arm.js +3 -1
- package/dist/runtime/idle-compaction.js +2 -1
- package/dist/runtime/run-finish.js +2 -1
- package/dist/runtime/run-jobs.js +2 -1
- package/dist/runtime/run-queue.js +4 -2
- package/dist/runtime/run-worker.js +5 -2
- package/dist/runtime/stream.js +10 -0
- package/dist/runtime/usage-report.js +2 -1
- package/dist/runtime/waits.js +2 -1
- package/dist/tools/approvals.service.js +6 -2
- package/dist/tools/builtins/skill-load.js +3 -2
- package/dist/tools/tool-watch.service.js +3 -1
- package/package.json +3 -3
- package/src/migrations/0227_external_conversations.sql +33 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
2
|
+
import type { KernelLogger } from "../log.js";
|
|
3
|
+
import { EffectiveConfigs } from "./effective-config.js";
|
|
4
|
+
import { ExtensionRegistry } from "./registry.js";
|
|
5
|
+
/**
|
|
6
|
+
* One provider of a multi-provider extension point for an org (`ExtensionPointDefaults`), with its
|
|
7
|
+
* effective deployment config for the org, to pass back to it.
|
|
8
|
+
*/
|
|
9
|
+
export interface PointProvider<T> {
|
|
10
|
+
extension: string;
|
|
11
|
+
impl: T;
|
|
12
|
+
config: unknown;
|
|
13
|
+
}
|
|
14
|
+
/** A provider that could serve an org now, with its effective config for the org. */
|
|
15
|
+
export interface Candidate {
|
|
16
|
+
extension: string;
|
|
17
|
+
impl: unknown;
|
|
18
|
+
config: unknown;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Whether one provider of an extension point serves an org now (web tools spec §6, layering spec
|
|
22
|
+
* A §6): loaded on this replica and providing the point, enabled in the org, a valid effective
|
|
23
|
+
* config for the org, and `configured(config)` not false. Per call, never cached in process.
|
|
24
|
+
* `ExtensionPointDefaults` evaluates its candidates through it; it sits below the extensions
|
|
25
|
+
* module (registry, effective configs and the database only), so the conversation access check
|
|
26
|
+
* (an external conversation is visible while its target serves the org) can inject it without a
|
|
27
|
+
* module cycle (writing-kernel-api: a cycle is cut by a shared provider both sides inject).
|
|
28
|
+
*/
|
|
29
|
+
export declare class ExtensionPointServing {
|
|
30
|
+
private readonly kdb;
|
|
31
|
+
private readonly registry;
|
|
32
|
+
private readonly effective;
|
|
33
|
+
private readonly log;
|
|
34
|
+
constructor(kdb: KernelDb, registry: Pick<ExtensionRegistry, "list">, effective: Pick<EffectiveConfigs, "get">, log: KernelLogger);
|
|
35
|
+
/**
|
|
36
|
+
* Whether the one provider `extension` of `point` (the name without the major) serves `orgId`
|
|
37
|
+
* now. A provider whose status cannot be read counts as not serving (logged to `log`, the
|
|
38
|
+
* caller's context logger when it passes one).
|
|
39
|
+
*/
|
|
40
|
+
serves(orgId: string, point: string, extension: string, log?: KernelLogger): Promise<boolean>;
|
|
41
|
+
/**
|
|
42
|
+
* The one provider `extension` of `point` when it {@link serves} `orgId` now, with its
|
|
43
|
+
* implementation and effective config for the org; null otherwise.
|
|
44
|
+
*/
|
|
45
|
+
providerOf<T>(orgId: string, point: string, extension: string, log?: KernelLogger): Promise<PointProvider<T> | null>;
|
|
46
|
+
/**
|
|
47
|
+
* The candidacy of a provider the caller found enabled in the org: a valid effective config and
|
|
48
|
+
* `configured(config)` not false. Undefined when it is off; a provider whose status could not be
|
|
49
|
+
* read is also added to `failed` and logged to `log` (the caller's context logger, so the warning
|
|
50
|
+
* names the service that excluded it).
|
|
51
|
+
*/
|
|
52
|
+
evaluate(orgId: string, point: string, extension: string, impl: unknown, failed: Set<string>, log?: KernelLogger): Promise<Candidate | undefined>;
|
|
53
|
+
}
|
|
54
|
+
/** The one {@link ExtensionPointServing} (below `ExtensionsModule`, which re-exports it). */
|
|
55
|
+
export declare class ExtensionPointServingModule {
|
|
56
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
+
};
|
|
10
|
+
import { Inject, Injectable, Module } from "@nestjs/common";
|
|
11
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
12
|
+
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
13
|
+
import { EffectiveConfigs } from "./effective-config.js";
|
|
14
|
+
import { isExtensionEnabled } from "./enabled.js";
|
|
15
|
+
import { ExtensionRegistry } from "./registry.js";
|
|
16
|
+
import { ExtensionStateModule } from "./state.module.js";
|
|
17
|
+
/**
|
|
18
|
+
* Whether one provider of an extension point serves an org now (web tools spec §6, layering spec
|
|
19
|
+
* A §6): loaded on this replica and providing the point, enabled in the org, a valid effective
|
|
20
|
+
* config for the org, and `configured(config)` not false. Per call, never cached in process.
|
|
21
|
+
* `ExtensionPointDefaults` evaluates its candidates through it; it sits below the extensions
|
|
22
|
+
* module (registry, effective configs and the database only), so the conversation access check
|
|
23
|
+
* (an external conversation is visible while its target serves the org) can inject it without a
|
|
24
|
+
* module cycle (writing-kernel-api: a cycle is cut by a shared provider both sides inject).
|
|
25
|
+
*/
|
|
26
|
+
let ExtensionPointServing = class ExtensionPointServing {
|
|
27
|
+
kdb;
|
|
28
|
+
registry;
|
|
29
|
+
effective;
|
|
30
|
+
log;
|
|
31
|
+
constructor(kdb, registry, effective, log) {
|
|
32
|
+
this.kdb = kdb;
|
|
33
|
+
this.registry = registry;
|
|
34
|
+
this.effective = effective;
|
|
35
|
+
this.log = log;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Whether the one provider `extension` of `point` (the name without the major) serves `orgId`
|
|
39
|
+
* now. A provider whose status cannot be read counts as not serving (logged to `log`, the
|
|
40
|
+
* caller's context logger when it passes one).
|
|
41
|
+
*/
|
|
42
|
+
async serves(orgId, point, extension, log = this.log) {
|
|
43
|
+
return (await this.providerOf(orgId, point, extension, log)) !== null;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The one provider `extension` of `point` when it {@link serves} `orgId` now, with its
|
|
47
|
+
* implementation and effective config for the org; null otherwise.
|
|
48
|
+
*/
|
|
49
|
+
async providerOf(orgId, point, extension, log = this.log) {
|
|
50
|
+
const entry = this.registry.list(point).find((e) => e.plugin === extension);
|
|
51
|
+
if (!entry || !(await isExtensionEnabled(this.kdb.db, orgId, extension)))
|
|
52
|
+
return null;
|
|
53
|
+
const c = await this.evaluate(orgId, point, extension, entry.impl, new Set(), log);
|
|
54
|
+
return c === undefined ? null : { extension: c.extension, impl: c.impl, config: c.config };
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The candidacy of a provider the caller found enabled in the org: a valid effective config and
|
|
58
|
+
* `configured(config)` not false. Undefined when it is off; a provider whose status could not be
|
|
59
|
+
* read is also added to `failed` and logged to `log` (the caller's context logger, so the warning
|
|
60
|
+
* names the service that excluded it).
|
|
61
|
+
*/
|
|
62
|
+
async evaluate(orgId, point, extension, impl, failed, log = this.log) {
|
|
63
|
+
// spec A §6: an org whose effective config is not valid gets no call from this extension
|
|
64
|
+
let effective;
|
|
65
|
+
try {
|
|
66
|
+
effective = await this.effective.get(orgId, extension);
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
log.warn("extension point provider excluded, cannot read its effective config", {
|
|
70
|
+
orgId,
|
|
71
|
+
point,
|
|
72
|
+
extension,
|
|
73
|
+
err,
|
|
74
|
+
});
|
|
75
|
+
failed.add(extension);
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
if (!effective.ok)
|
|
79
|
+
return undefined;
|
|
80
|
+
const configured = impl.configured;
|
|
81
|
+
if (typeof configured === "function") {
|
|
82
|
+
let ok;
|
|
83
|
+
try {
|
|
84
|
+
ok = configured.call(impl, effective.config) !== false;
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
log.warn("extension point provider excluded, configured() threw", {
|
|
88
|
+
orgId,
|
|
89
|
+
point,
|
|
90
|
+
extension,
|
|
91
|
+
err,
|
|
92
|
+
});
|
|
93
|
+
failed.add(extension);
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
if (!ok)
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
return { extension, impl, config: effective.config };
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
ExtensionPointServing = __decorate([
|
|
103
|
+
Injectable(),
|
|
104
|
+
__param(0, Inject(KernelDb)),
|
|
105
|
+
__param(1, Inject(ExtensionRegistry)),
|
|
106
|
+
__param(2, Inject(EffectiveConfigs)),
|
|
107
|
+
__param(3, Inject(KERNEL_LOGGER))
|
|
108
|
+
], ExtensionPointServing);
|
|
109
|
+
export { ExtensionPointServing };
|
|
110
|
+
/** The one {@link ExtensionPointServing} (below `ExtensionsModule`, which re-exports it). */
|
|
111
|
+
let ExtensionPointServingModule = class ExtensionPointServingModule {
|
|
112
|
+
};
|
|
113
|
+
ExtensionPointServingModule = __decorate([
|
|
114
|
+
Module({
|
|
115
|
+
imports: [ExtensionStateModule],
|
|
116
|
+
providers: [ExtensionPointServing],
|
|
117
|
+
exports: [ExtensionPointServing],
|
|
118
|
+
})
|
|
119
|
+
], ExtensionPointServingModule);
|
|
120
|
+
export { ExtensionPointServingModule };
|
|
@@ -93,6 +93,17 @@ export declare class InboxItemsService {
|
|
|
93
93
|
* unknown id throws `InboxError("not_found")`. The caller runs it in the org's scope.
|
|
94
94
|
*/
|
|
95
95
|
resolveForPlugin(plugin: string, orgId: string, itemId: string): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Resolves the open kernel item of `accountId` in `orgId` posted with `dedupeKey` (the thing it
|
|
98
|
+
* asked about was settled elsewhere); none open is no change. The caller runs it in the org's
|
|
99
|
+
* scope.
|
|
100
|
+
*/
|
|
101
|
+
resolveKernelItem(orgId: string, accountId: string, dedupeKey: string): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Resolves every open kernel item of `accountId` in `orgId` whose dedupe key starts with
|
|
104
|
+
* `prefix` (the things they asked about are gone). The caller runs it in the org's scope.
|
|
105
|
+
*/
|
|
106
|
+
resolveKernelItems(orgId: string, accountId: string, prefix: string): Promise<void>;
|
|
96
107
|
/** Marks an open item resolved; whether it was open. */
|
|
97
108
|
close(orgId: string, itemId: string): Promise<boolean>;
|
|
98
109
|
/** The open, unexpired item `itemId` of `accountId` in `orgId`, or `inbox.item_not_found`. */
|
|
@@ -222,6 +222,39 @@ let InboxItemsService = class InboxItemsService {
|
|
|
222
222
|
throw new InboxError("not_found", "inbox item not found");
|
|
223
223
|
await this.close(orgId, itemId);
|
|
224
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Resolves the open kernel item of `accountId` in `orgId` posted with `dedupeKey` (the thing it
|
|
227
|
+
* asked about was settled elsewhere); none open is no change. The caller runs it in the org's
|
|
228
|
+
* scope.
|
|
229
|
+
*/
|
|
230
|
+
async resolveKernelItem(orgId, accountId, dedupeKey) {
|
|
231
|
+
await this.kdb.db
|
|
232
|
+
.updateTable("inbox_items")
|
|
233
|
+
.set({ state: "resolved", resolved_at: sql `now()` })
|
|
234
|
+
.where("org_id", "=", orgId)
|
|
235
|
+
.where("account_id", "=", accountId)
|
|
236
|
+
.where("source", "=", "kernel")
|
|
237
|
+
.where("plugin", "is", null)
|
|
238
|
+
.where("dedupe_key", "=", dedupeKey)
|
|
239
|
+
.where("state", "=", "open")
|
|
240
|
+
.execute();
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Resolves every open kernel item of `accountId` in `orgId` whose dedupe key starts with
|
|
244
|
+
* `prefix` (the things they asked about are gone). The caller runs it in the org's scope.
|
|
245
|
+
*/
|
|
246
|
+
async resolveKernelItems(orgId, accountId, prefix) {
|
|
247
|
+
await this.kdb.db
|
|
248
|
+
.updateTable("inbox_items")
|
|
249
|
+
.set({ state: "resolved", resolved_at: sql `now()` })
|
|
250
|
+
.where("org_id", "=", orgId)
|
|
251
|
+
.where("account_id", "=", accountId)
|
|
252
|
+
.where("source", "=", "kernel")
|
|
253
|
+
.where("plugin", "is", null)
|
|
254
|
+
.where(sql `starts_with(dedupe_key, ${prefix})`)
|
|
255
|
+
.where("state", "=", "open")
|
|
256
|
+
.execute();
|
|
257
|
+
}
|
|
225
258
|
/** Marks an open item resolved; whether it was open. */
|
|
226
259
|
async close(orgId, itemId) {
|
|
227
260
|
const r = await this.kdb.db
|
|
@@ -326,6 +359,12 @@ __decorate([
|
|
|
326
359
|
__decorate([
|
|
327
360
|
Transactional()
|
|
328
361
|
], InboxItemsService.prototype, "resolveForPlugin", null);
|
|
362
|
+
__decorate([
|
|
363
|
+
Transactional()
|
|
364
|
+
], InboxItemsService.prototype, "resolveKernelItem", null);
|
|
365
|
+
__decorate([
|
|
366
|
+
Transactional()
|
|
367
|
+
], InboxItemsService.prototype, "resolveKernelItems", null);
|
|
329
368
|
__decorate([
|
|
330
369
|
Transactional()
|
|
331
370
|
], InboxItemsService.prototype, "close", null);
|
|
@@ -610,6 +610,76 @@ export declare const OUTBOX_JOBS: {
|
|
|
610
610
|
readonly removeOnFail: true;
|
|
611
611
|
};
|
|
612
612
|
};
|
|
613
|
+
readonly "external-start": {
|
|
614
|
+
readonly queue: "cap-external-calls";
|
|
615
|
+
readonly idempotent: "the delivery goes only while its deliverySeq is the next after the conversation's cursor, which it moves when done; the target's start is idempotent by messageId";
|
|
616
|
+
readonly processedIn: "packages/kernel/src/conversations/external/external-calls.processor.ts";
|
|
617
|
+
readonly opts: {
|
|
618
|
+
readonly attempts: 10;
|
|
619
|
+
readonly backoff: {
|
|
620
|
+
readonly type: "exponential";
|
|
621
|
+
readonly delay: 2000;
|
|
622
|
+
};
|
|
623
|
+
readonly removeOnComplete: true;
|
|
624
|
+
readonly removeOnFail: true;
|
|
625
|
+
};
|
|
626
|
+
};
|
|
627
|
+
readonly "external-send": {
|
|
628
|
+
readonly queue: "cap-external-calls";
|
|
629
|
+
readonly idempotent: "the delivery goes only while its deliverySeq is the next after the conversation's cursor, which it moves when done; the target's send is idempotent by messageId";
|
|
630
|
+
readonly processedIn: "packages/kernel/src/conversations/external/external-calls.processor.ts";
|
|
631
|
+
readonly opts: {
|
|
632
|
+
readonly attempts: 10;
|
|
633
|
+
readonly backoff: {
|
|
634
|
+
readonly type: "exponential";
|
|
635
|
+
readonly delay: 2000;
|
|
636
|
+
};
|
|
637
|
+
readonly removeOnComplete: true;
|
|
638
|
+
readonly removeOnFail: true;
|
|
639
|
+
};
|
|
640
|
+
};
|
|
641
|
+
readonly "external-answer": {
|
|
642
|
+
readonly queue: "cap-external-calls";
|
|
643
|
+
readonly idempotent: "the answer is written once per request (its idempotency key); the target's answer is idempotent by requestId";
|
|
644
|
+
readonly processedIn: "packages/kernel/src/conversations/external/external-calls.processor.ts";
|
|
645
|
+
readonly opts: {
|
|
646
|
+
readonly attempts: 10;
|
|
647
|
+
readonly backoff: {
|
|
648
|
+
readonly type: "exponential";
|
|
649
|
+
readonly delay: 2000;
|
|
650
|
+
};
|
|
651
|
+
readonly removeOnComplete: true;
|
|
652
|
+
readonly removeOnFail: true;
|
|
653
|
+
};
|
|
654
|
+
};
|
|
655
|
+
readonly "external-stop": {
|
|
656
|
+
readonly queue: "cap-external-calls";
|
|
657
|
+
readonly idempotent: "stopping a turn that is not running is a no-op for the target; the job id is per conversation and last seq";
|
|
658
|
+
readonly processedIn: "packages/kernel/src/conversations/external/external-calls.processor.ts";
|
|
659
|
+
readonly opts: {
|
|
660
|
+
readonly attempts: 10;
|
|
661
|
+
readonly backoff: {
|
|
662
|
+
readonly type: "exponential";
|
|
663
|
+
readonly delay: 2000;
|
|
664
|
+
};
|
|
665
|
+
readonly removeOnComplete: true;
|
|
666
|
+
readonly removeOnFail: true;
|
|
667
|
+
};
|
|
668
|
+
};
|
|
669
|
+
readonly "external-deleted": {
|
|
670
|
+
readonly queue: "cap-external-calls";
|
|
671
|
+
readonly idempotent: "releasing what the target holds for a deleted conversation twice releases nothing more; the job id is per conversation and last seq";
|
|
672
|
+
readonly processedIn: "packages/kernel/src/conversations/external/external-calls.processor.ts";
|
|
673
|
+
readonly opts: {
|
|
674
|
+
readonly attempts: 10;
|
|
675
|
+
readonly backoff: {
|
|
676
|
+
readonly type: "exponential";
|
|
677
|
+
readonly delay: 2000;
|
|
678
|
+
};
|
|
679
|
+
readonly removeOnComplete: true;
|
|
680
|
+
readonly removeOnFail: true;
|
|
681
|
+
};
|
|
682
|
+
};
|
|
613
683
|
readonly "hook-run-lifecycle": {
|
|
614
684
|
readonly queue: "cap-kernel-lifecycle";
|
|
615
685
|
readonly idempotent: "the `run.lifecycle` handler sets a display state keyed by the run and phase (the SDK contract: handlers are idempotent); the job id is deterministic per run, phase and wait";
|
|
@@ -16,6 +16,17 @@ const SCOPE_JOB_OPTS = {
|
|
|
16
16
|
removeOnComplete: true,
|
|
17
17
|
removeOnFail: true,
|
|
18
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* The external conversation calls' retry policy: 10 attempts from 2 s, doubling (about 17 min in
|
|
21
|
+
* all) before the call is dropped with a failed turn; removed once done, so the same id owed again
|
|
22
|
+
* (a chained send) is not deduped away.
|
|
23
|
+
*/
|
|
24
|
+
const EXTERNAL_CALL_OPTS = {
|
|
25
|
+
attempts: 10,
|
|
26
|
+
backoff: { type: "exponential", delay: 2_000 },
|
|
27
|
+
removeOnComplete: true,
|
|
28
|
+
removeOnFail: true,
|
|
29
|
+
};
|
|
19
30
|
/**
|
|
20
31
|
* Every job name added through the outbox. The task that introduces a job name adds its entry; a
|
|
21
32
|
* name without one does not type-check as an `OutboxJobName` (`add` does not check it at runtime).
|
|
@@ -554,6 +565,39 @@ export const OUTBOX_JOBS = {
|
|
|
554
565
|
removeOnFail: true,
|
|
555
566
|
},
|
|
556
567
|
},
|
|
568
|
+
// `conversations/external/external-calls.ts` EXTERNAL_CALL_JOBS: owed by the transaction that
|
|
569
|
+
// writes a person's message to an external conversation (start, send), their answer to its
|
|
570
|
+
// request, a stop, or its deletion (local agents spec Part 2), under `externalCallJob`
|
|
571
|
+
"external-start": {
|
|
572
|
+
queue: "cap-external-calls",
|
|
573
|
+
idempotent: "the delivery goes only while its deliverySeq is the next after the conversation's cursor, which it moves when done; the target's start is idempotent by messageId",
|
|
574
|
+
processedIn: "packages/kernel/src/conversations/external/external-calls.processor.ts",
|
|
575
|
+
opts: EXTERNAL_CALL_OPTS,
|
|
576
|
+
},
|
|
577
|
+
"external-send": {
|
|
578
|
+
queue: "cap-external-calls",
|
|
579
|
+
idempotent: "the delivery goes only while its deliverySeq is the next after the conversation's cursor, which it moves when done; the target's send is idempotent by messageId",
|
|
580
|
+
processedIn: "packages/kernel/src/conversations/external/external-calls.processor.ts",
|
|
581
|
+
opts: EXTERNAL_CALL_OPTS,
|
|
582
|
+
},
|
|
583
|
+
"external-answer": {
|
|
584
|
+
queue: "cap-external-calls",
|
|
585
|
+
idempotent: "the answer is written once per request (its idempotency key); the target's answer is idempotent by requestId",
|
|
586
|
+
processedIn: "packages/kernel/src/conversations/external/external-calls.processor.ts",
|
|
587
|
+
opts: EXTERNAL_CALL_OPTS,
|
|
588
|
+
},
|
|
589
|
+
"external-stop": {
|
|
590
|
+
queue: "cap-external-calls",
|
|
591
|
+
idempotent: "stopping a turn that is not running is a no-op for the target; the job id is per conversation and last seq",
|
|
592
|
+
processedIn: "packages/kernel/src/conversations/external/external-calls.processor.ts",
|
|
593
|
+
opts: EXTERNAL_CALL_OPTS,
|
|
594
|
+
},
|
|
595
|
+
"external-deleted": {
|
|
596
|
+
queue: "cap-external-calls",
|
|
597
|
+
idempotent: "releasing what the target holds for a deleted conversation twice releases nothing more; the job id is per conversation and last seq",
|
|
598
|
+
processedIn: "packages/kernel/src/conversations/external/external-calls.processor.ts",
|
|
599
|
+
opts: EXTERNAL_CALL_OPTS,
|
|
600
|
+
},
|
|
557
601
|
// `extensions/run-lifecycle-owe.ts` RUN_LIFECYCLE_JOB: owed by the transaction that starts a
|
|
558
602
|
// run, suspends it on a person, resumes it, ends it (finished, failed, aborted) or declines,
|
|
559
603
|
// expires or gives up on directed work, once per phase of a run (and wait) and plugin
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* (admin/health.service.ts) lists the same names from the feature constants;
|
|
5
5
|
* test/infra/queue-names.test.ts keeps the two equal.
|
|
6
6
|
*/
|
|
7
|
-
export declare const KERNEL_QUEUES: readonly ["cap-kernel-runs", "cap-kernel-subagent-runs", "cap-kernel-channels", "cap-kernel-maintenance", "cap-kernel-tool-watch", "cap-kernel-plugin-scope", "cap-kernel-titles", "cap-kernel-suggestions", "cap-kernel-usage-report", "cap-kernel-evals", "cap-kernel-lifecycle", "cap-push-deliver", "cap-connector-tools", "cap-template-connectors", "cap-device-service-events"];
|
|
7
|
+
export declare const KERNEL_QUEUES: readonly ["cap-kernel-runs", "cap-kernel-subagent-runs", "cap-kernel-channels", "cap-kernel-maintenance", "cap-kernel-tool-watch", "cap-kernel-plugin-scope", "cap-kernel-titles", "cap-kernel-suggestions", "cap-kernel-usage-report", "cap-kernel-evals", "cap-kernel-lifecycle", "cap-push-deliver", "cap-connector-tools", "cap-template-connectors", "cap-device-service-events", "cap-external-calls"];
|
|
8
8
|
export type KernelQueueName = (typeof KERNEL_QUEUES)[number];
|
package/dist/kernel.module.js
CHANGED
|
@@ -11,6 +11,7 @@ import { TriggerEventsModule } from "./automations/events/events.module.js";
|
|
|
11
11
|
import { CatalogModule } from "./catalog/catalog.module.js";
|
|
12
12
|
import { ChannelsModule } from "./channels/channels.module.js";
|
|
13
13
|
import { ClientModule } from "./client/client.module.js";
|
|
14
|
+
import { ExternalConversationsModule } from "./conversations/external/external-conversations.service.js";
|
|
14
15
|
import { PromptSuggestionsModule } from "./conversations/prompt-suggestions.js";
|
|
15
16
|
import { TitlesModule } from "./conversations/titles.js";
|
|
16
17
|
import { ExtensionDeviceAccessModule } from "./device-access/device-access.module.js";
|
|
@@ -143,6 +144,9 @@ let KernelModule = KernelModule_1 = class KernelModule {
|
|
|
143
144
|
InboxItemsModule,
|
|
144
145
|
// ctx.agents / ctx.conversations / ctx.people: read-only org facts (found at the time of use)
|
|
145
146
|
PluginReadsModule,
|
|
147
|
+
// ctx.conversations' external methods and the external conversation calls' queue (found at
|
|
148
|
+
// the time of use)
|
|
149
|
+
ExternalConversationsModule,
|
|
146
150
|
// the Platform tool's operation registry and actor facts
|
|
147
151
|
PlatformModule,
|
|
148
152
|
// its operations (skills, agents, ...), registered at start on every role
|
|
@@ -24,6 +24,16 @@ export const PLATFORM_EXCLUSIONS = [
|
|
|
24
24
|
category: "human-only",
|
|
25
25
|
reason: "Interactive owner session permission selection and device-bound consent",
|
|
26
26
|
},
|
|
27
|
+
{
|
|
28
|
+
route: "GET /api/v1/orgs/:orgId/conversation-targets",
|
|
29
|
+
category: "human-only",
|
|
30
|
+
reason: "lists the person's local agents for the web new conversation page",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
route: "POST /api/v1/orgs/:orgId/conversations/:id/external-requests/:requestId",
|
|
34
|
+
category: "human-only",
|
|
35
|
+
reason: "the person decides a local agent's request",
|
|
36
|
+
},
|
|
27
37
|
{
|
|
28
38
|
route: "POST /api/v1/admin/accounts/:accountId/erasure",
|
|
29
39
|
category: "human-only",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type OnModuleInit } from "@nestjs/common";
|
|
2
2
|
import { ConversationsService } from "../../conversations/conversations.service.js";
|
|
3
3
|
import { ConversationDeviceStatus } from "../../conversations/device-status.js";
|
|
4
|
+
import { ExternalConversationsService } from "../../conversations/external/external-conversations.service.js";
|
|
4
5
|
import { ConversationFiles } from "../../conversations/files.js";
|
|
5
6
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
6
7
|
import { PlatformOperations } from "../registry.js";
|
|
@@ -16,7 +17,11 @@ export declare class ConversationsOperations implements OnModuleInit {
|
|
|
16
17
|
private readonly files;
|
|
17
18
|
private readonly device;
|
|
18
19
|
private readonly kdb;
|
|
19
|
-
|
|
20
|
+
/** An external conversation's stop (local agents spec Part 2). */
|
|
21
|
+
private readonly external;
|
|
22
|
+
constructor(registry: PlatformOperations, conversations: ConversationsService, files: ConversationFiles, device: ConversationDeviceStatus, kdb: KernelDb,
|
|
23
|
+
/** An external conversation's stop (local agents spec Part 2). */
|
|
24
|
+
external: Pick<ExternalConversationsService, "find" | "stop">);
|
|
20
25
|
/**
|
|
21
26
|
* Whether `id` is the conversation this run belongs to: its ROOT (the Platform tool also runs in
|
|
22
27
|
* sub-agents, whose own id is not the person's conversation). Stopping or deleting it would end
|
|
@@ -25,6 +30,8 @@ export declare class ConversationsOperations implements OnModuleInit {
|
|
|
25
30
|
private isRunsRoot;
|
|
26
31
|
private titleOf;
|
|
27
32
|
private precheckWritable;
|
|
33
|
+
/** A change of the conversation itself (rename, archive, delete): external ones included. */
|
|
34
|
+
private precheckOwned;
|
|
28
35
|
private setArchived;
|
|
29
36
|
onModuleInit(): void;
|
|
30
37
|
}
|
|
@@ -9,9 +9,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
9
9
|
};
|
|
10
10
|
import { Inject, Injectable } from "@nestjs/common";
|
|
11
11
|
import { z } from "zod";
|
|
12
|
-
import { EventsQuery, FilesQuery, IdParams, ListQuery, PatchBody, SubagentsQuery, } from "../../conversations/conversations.schemas.js";
|
|
12
|
+
import { EventsQuery, FilesQuery, IdParams, ListQuery, PatchBody, SubagentsQuery, targetRefOf, } from "../../conversations/conversations.schemas.js";
|
|
13
13
|
import { ConversationsService, } from "../../conversations/conversations.service.js";
|
|
14
14
|
import { ConversationDeviceStatus } from "../../conversations/device-status.js";
|
|
15
|
+
import { ExternalConversationsService } from "../../conversations/external/external-conversations.service.js";
|
|
15
16
|
import { ConversationFiles } from "../../conversations/files.js";
|
|
16
17
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
17
18
|
import { rootConversationOf } from "../../runtime/subagents/child.js";
|
|
@@ -23,13 +24,24 @@ const PAGE = 50;
|
|
|
23
24
|
const ConversationId = IdParams.shape.id;
|
|
24
25
|
const Id = z.object({ conversationId: ConversationId }).strict();
|
|
25
26
|
const EVENTS_PAGE_MAX = 100;
|
|
26
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* A list row: the compact form (`state` is what the run is doing, else archived or idle; an
|
|
29
|
+
* external conversation has no agent and names its local agent in `target`).
|
|
30
|
+
*/
|
|
27
31
|
const row = (c) => ({
|
|
28
32
|
id: c.id,
|
|
29
33
|
name: c.title ?? "Untitled",
|
|
34
|
+
kind: c.kind,
|
|
30
35
|
state: c.activity ?? (c.archivedAt === null ? "idle" : "archived"),
|
|
31
36
|
agentId: c.agentId,
|
|
32
37
|
agent: c.agent,
|
|
38
|
+
target: c.external === null
|
|
39
|
+
? null
|
|
40
|
+
: {
|
|
41
|
+
extension: c.external.extension,
|
|
42
|
+
targetKey: c.external.targetKey,
|
|
43
|
+
label: c.external.label,
|
|
44
|
+
},
|
|
33
45
|
updatedAt: c.updatedAt,
|
|
34
46
|
});
|
|
35
47
|
/**
|
|
@@ -44,12 +56,16 @@ let ConversationsOperations = class ConversationsOperations {
|
|
|
44
56
|
files;
|
|
45
57
|
device;
|
|
46
58
|
kdb;
|
|
47
|
-
|
|
59
|
+
external;
|
|
60
|
+
constructor(registry, conversations, files, device, kdb,
|
|
61
|
+
/** An external conversation's stop (local agents spec Part 2). */
|
|
62
|
+
external) {
|
|
48
63
|
this.registry = registry;
|
|
49
64
|
this.conversations = conversations;
|
|
50
65
|
this.files = files;
|
|
51
66
|
this.device = device;
|
|
52
67
|
this.kdb = kdb;
|
|
68
|
+
this.external = external;
|
|
53
69
|
}
|
|
54
70
|
/**
|
|
55
71
|
* Whether `id` is the conversation this run belongs to: its ROOT (the Platform tool also runs in
|
|
@@ -66,6 +82,10 @@ let ConversationsOperations = class ConversationsOperations {
|
|
|
66
82
|
precheckWritable(id, ctx) {
|
|
67
83
|
return precheckBy(() => this.conversations.writable(ctx.orgId, id, ctx.actorAccountId));
|
|
68
84
|
}
|
|
85
|
+
/** A change of the conversation itself (rename, archive, delete): external ones included. */
|
|
86
|
+
precheckOwned(id, ctx) {
|
|
87
|
+
return precheckBy(() => this.conversations.owned(ctx.orgId, id, ctx.actorAccountId));
|
|
88
|
+
}
|
|
69
89
|
async setArchived(id, archived, ctx) {
|
|
70
90
|
return {
|
|
71
91
|
conversation: await this.conversations.setArchived(ctx.orgId, id, ctx.actorAccountId, archived),
|
|
@@ -75,12 +95,13 @@ let ConversationsOperations = class ConversationsOperations {
|
|
|
75
95
|
this.registry.register([
|
|
76
96
|
defineOperation({
|
|
77
97
|
id: "conversations.list",
|
|
78
|
-
description: "List your own conversations, most recently updated first: id, name, state (running, waiting, idle or archived), agent (id, name, profile; null when no longer visible) and update time. Pages by 50: pass the returned next as params.after; the first page (no after) also returns total, the count of all matches. Filter by title text q, by agentId, by state (running or waiting), or pass archived 1 for the archived ones.",
|
|
98
|
+
description: "List your own conversations, most recently updated first: id, name, kind (chat, or external: held with a local agent on your device, which has no agentId and names it in target), state (running, waiting, idle or archived), agentId and agent (id, name, profile; null when no longer visible), target (extension, targetKey, label; null for a chat) and update time. Pages by 50: pass the returned next as params.after; the first page (no after) also returns total, the count of all matches. Filter by title text q, by agentId, by target (extension/targetKey), by state (running or waiting), or pass archived 1 for the archived ones.",
|
|
79
99
|
input: ListQuery.pick({
|
|
80
100
|
q: true,
|
|
81
101
|
state: true,
|
|
82
102
|
archived: true,
|
|
83
103
|
agentId: true,
|
|
104
|
+
target: true,
|
|
84
105
|
after: true,
|
|
85
106
|
}).strict(),
|
|
86
107
|
example: { q: "report" },
|
|
@@ -95,6 +116,7 @@ let ConversationsOperations = class ConversationsOperations {
|
|
|
95
116
|
total: input.after === undefined,
|
|
96
117
|
...(input.after !== undefined && { after: input.after }),
|
|
97
118
|
...(input.agentId !== undefined && { agentId: input.agentId }),
|
|
119
|
+
...(input.target !== undefined && { target: targetRefOf(input.target) }),
|
|
98
120
|
...(input.q !== undefined && { q: input.q }),
|
|
99
121
|
...(input.state !== undefined && { state: input.state }),
|
|
100
122
|
...(input.archived !== undefined && { archived: true }),
|
|
@@ -188,7 +210,7 @@ let ConversationsOperations = class ConversationsOperations {
|
|
|
188
210
|
},
|
|
189
211
|
],
|
|
190
212
|
confirm: "personal",
|
|
191
|
-
precheck: (i, ctx) =>
|
|
213
|
+
precheck: (i, ctx) => this.precheckOwned(i.conversationId, ctx),
|
|
192
214
|
summary: async (i, ctx) => {
|
|
193
215
|
const old = await this.titleOf(ctx, i.conversationId);
|
|
194
216
|
return {
|
|
@@ -221,7 +243,7 @@ let ConversationsOperations = class ConversationsOperations {
|
|
|
221
243
|
},
|
|
222
244
|
],
|
|
223
245
|
confirm: "personal",
|
|
224
|
-
precheck: (i, ctx) => this.
|
|
246
|
+
precheck: (i, ctx) => this.precheckOwned(i.conversationId, ctx),
|
|
225
247
|
summary: async (i, ctx) => {
|
|
226
248
|
const t = await this.titleOf(ctx, i.conversationId);
|
|
227
249
|
return { zh: `归档对话「${t}」`, en: `Archive conversation "${t}"` };
|
|
@@ -248,7 +270,7 @@ let ConversationsOperations = class ConversationsOperations {
|
|
|
248
270
|
},
|
|
249
271
|
],
|
|
250
272
|
confirm: "personal",
|
|
251
|
-
precheck: (i, ctx) => this.
|
|
273
|
+
precheck: (i, ctx) => this.precheckOwned(i.conversationId, ctx),
|
|
252
274
|
summary: async (i, ctx) => {
|
|
253
275
|
const t = await this.titleOf(ctx, i.conversationId);
|
|
254
276
|
return { zh: `取消归档对话「${t}」`, en: `Unarchive conversation "${t}"` };
|
|
@@ -372,7 +394,7 @@ let ConversationsOperations = class ConversationsOperations {
|
|
|
372
394
|
}),
|
|
373
395
|
defineOperation({
|
|
374
396
|
id: "conversations.abort",
|
|
375
|
-
description: "Stop the run that is active in one of your other conversations (its sub-agents stop with it; stopping a sub-agent's conversation stops it and those below it). Nothing happens if no run is active. The conversation you are working in cannot be stopped.",
|
|
397
|
+
description: "Stop the run that is active in one of your other conversations (its sub-agents stop with it; stopping a sub-agent's conversation stops it and those below it). Nothing happens if no run is active. For an external conversation (kind external) its local agent is asked to stop its current turn (runId null). The conversation you are working in cannot be stopped.",
|
|
376
398
|
input: Id,
|
|
377
399
|
example: { conversationId: "3f2b8a40-6c1d-4e0b-9a77-5d1e2c8b9f10" },
|
|
378
400
|
authz: { orgAction: "agents.use" },
|
|
@@ -383,6 +405,10 @@ let ConversationsOperations = class ConversationsOperations {
|
|
|
383
405
|
code: "conversation.not_found",
|
|
384
406
|
next: "Check the id with conversations.list: only your own conversations can be read or changed.",
|
|
385
407
|
},
|
|
408
|
+
{
|
|
409
|
+
code: "conversation.target_unavailable",
|
|
410
|
+
next: "The local agent of that conversation is not available in this organization now; ask the person to check its plugin.",
|
|
411
|
+
},
|
|
386
412
|
{
|
|
387
413
|
code: "run.not_active",
|
|
388
414
|
next: "No run is active in that conversation: nothing to stop; check conversations.list for its state.",
|
|
@@ -411,10 +437,17 @@ let ConversationsOperations = class ConversationsOperations {
|
|
|
411
437
|
en: `Stop the active run in conversation "${t}"`,
|
|
412
438
|
};
|
|
413
439
|
},
|
|
414
|
-
run: async (input, ctx) =>
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
440
|
+
run: async (input, ctx) => {
|
|
441
|
+
// an external conversation has no runs: its local agent is asked to stop (owed)
|
|
442
|
+
if (await this.external.find(ctx.orgId, input.conversationId, ctx.actorAccountId)) {
|
|
443
|
+
await this.external.stop(ctx.orgId, input.conversationId, ctx.actorAccountId);
|
|
444
|
+
return { stopped: true, runId: null };
|
|
445
|
+
}
|
|
446
|
+
return {
|
|
447
|
+
stopped: true,
|
|
448
|
+
runId: await this.conversations.abort(ctx.orgId, input.conversationId, ctx.actorAccountId),
|
|
449
|
+
};
|
|
450
|
+
},
|
|
418
451
|
}),
|
|
419
452
|
defineOperation({
|
|
420
453
|
id: "conversations.compact",
|
|
@@ -439,6 +472,10 @@ let ConversationsOperations = class ConversationsOperations {
|
|
|
439
472
|
code: "conversation.read_only",
|
|
440
473
|
next: "That is a sub-agent's conversation and is compacted by its own runs; compact the conversation it belongs to.",
|
|
441
474
|
},
|
|
475
|
+
{
|
|
476
|
+
code: "conversation.external_read_only",
|
|
477
|
+
next: "That conversation is with a local agent and does not run here: Capybara does not compact it.",
|
|
478
|
+
},
|
|
442
479
|
],
|
|
443
480
|
confirm: "personal",
|
|
444
481
|
precheck: (i, ctx) => this.precheckWritable(i.conversationId, ctx),
|
|
@@ -483,7 +520,7 @@ let ConversationsOperations = class ConversationsOperations {
|
|
|
483
520
|
message: "The conversation you are running in cannot be deleted from here.",
|
|
484
521
|
};
|
|
485
522
|
}
|
|
486
|
-
return
|
|
523
|
+
return this.precheckOwned(i.conversationId, ctx);
|
|
487
524
|
},
|
|
488
525
|
summary: async (i, ctx) => {
|
|
489
526
|
const t = await this.titleOf(ctx, i.conversationId);
|
|
@@ -503,6 +540,7 @@ ConversationsOperations = __decorate([
|
|
|
503
540
|
__param(1, Inject(ConversationsService)),
|
|
504
541
|
__param(2, Inject(ConversationFiles)),
|
|
505
542
|
__param(3, Inject(ConversationDeviceStatus)),
|
|
506
|
-
__param(4, Inject(KernelDb))
|
|
543
|
+
__param(4, Inject(KernelDb)),
|
|
544
|
+
__param(5, Inject(ExternalConversationsService))
|
|
507
545
|
], ConversationsOperations);
|
|
508
546
|
export { ConversationsOperations };
|