@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
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Kernel-issued person handles (`DevicePersonHandle`, local agents spec, call 6): the kernel puts
|
|
3
|
-
* one on the args of each org `ctx.ui.action` / `ctx.ui.query` handler call
|
|
4
|
-
* call runs for, and revokes it when the
|
|
5
|
-
* is admitted only for a live handle, and the org
|
|
6
|
-
*
|
|
7
|
-
*
|
|
3
|
+
* one on the args of each org `ctx.ui.action` / `ctx.ui.query` handler call and of each
|
|
4
|
+
* `conversation-target@1` call, for the person the call runs for, and revokes it when the call
|
|
5
|
+
* settles. A host service call with a person scope is admitted only for a live handle, and the org
|
|
6
|
+
* and account come from it, never from the extension; a handle bound to a device (a call about an
|
|
7
|
+
* external conversation: its device) is admitted for that device only. Per call and per process
|
|
8
|
+
* like a tool call's scope (`tools/call-scope.ts`): the handle never leaves the process that issued
|
|
9
|
+
* it, and nothing is shared across replicas.
|
|
8
10
|
*/
|
|
9
11
|
const persons = new WeakMap();
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
+
/**
|
|
13
|
+
* A new handle for `accountId` in `orgId`, live until {@link revokePersonHandle}; with `deviceId`,
|
|
14
|
+
* valid for that device only (null: for no device).
|
|
15
|
+
*/
|
|
16
|
+
export function issuePersonHandle(orgId, accountId, deviceId) {
|
|
12
17
|
const handle = Object.freeze({ kind: "device-person" });
|
|
13
|
-
persons.set(handle, { orgId, accountId });
|
|
18
|
+
persons.set(handle, { orgId, accountId, ...(deviceId !== undefined && { deviceId }) });
|
|
14
19
|
return handle;
|
|
15
20
|
}
|
|
16
21
|
/** Ends the handle: later host service calls with it are refused. */
|
|
17
22
|
export function revokePersonHandle(handle) {
|
|
18
23
|
persons.delete(handle);
|
|
19
24
|
}
|
|
20
|
-
/** The org and
|
|
25
|
+
/** The org, account (and bound device) of a live handle the kernel issued; null for anything else. */
|
|
21
26
|
export function personOf(handle) {
|
|
22
27
|
if (typeof handle !== "object" || handle === null)
|
|
23
28
|
return null;
|
|
@@ -113,6 +113,11 @@ export declare class ConversationDevices {
|
|
|
113
113
|
* has no default device and none can be made (no default provider on in the org).
|
|
114
114
|
*/
|
|
115
115
|
forNew(orgId: string, accountId: string, pick?: NewConversationDevice): Promise<string | null>;
|
|
116
|
+
/**
|
|
117
|
+
* The person's default device in the org when they already have one, else null; unlike
|
|
118
|
+
* {@link forNew}, never makes one (no access check: a caller binding it checks it as a choice).
|
|
119
|
+
*/
|
|
120
|
+
existingDefault(orgId: string, accountId: string): Promise<string | null>;
|
|
116
121
|
/**
|
|
117
122
|
* The device a sandbox tool call of the conversation tree rooted at `rootConversationId`
|
|
118
123
|
* enters, checked for its owner now. A conversation still unbound (created before
|
|
@@ -149,6 +149,22 @@ let ConversationDevices = class ConversationDevices {
|
|
|
149
149
|
return null;
|
|
150
150
|
return this.defaultFor(orgId, accountId, pick.im === true);
|
|
151
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* The person's default device in the org when they already have one, else null; unlike
|
|
154
|
+
* {@link forNew}, never makes one (no access check: a caller binding it checks it as a choice).
|
|
155
|
+
*/
|
|
156
|
+
async existingDefault(orgId, accountId) {
|
|
157
|
+
const row = await this.db
|
|
158
|
+
.selectFrom("devices")
|
|
159
|
+
.select("id")
|
|
160
|
+
.where("org_id", "=", orgId)
|
|
161
|
+
.where("owner_kind", "=", "personal")
|
|
162
|
+
.where("owner_account_id", "=", accountId)
|
|
163
|
+
.where("is_default", "=", true)
|
|
164
|
+
.where("deleted_at", "is", null)
|
|
165
|
+
.executeTakeFirst();
|
|
166
|
+
return row?.id ?? null;
|
|
167
|
+
}
|
|
152
168
|
/**
|
|
153
169
|
* The device a sandbox tool call of the conversation tree rooted at `rootConversationId`
|
|
154
170
|
* enters, checked for its owner now. A conversation still unbound (created before
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { sql } from "kysely";
|
|
2
|
-
// PostgreSQL 17 after
|
|
2
|
+
// PostgreSQL 17 after 0227. Re-review the ownership map before updating this fingerprint.
|
|
3
3
|
// It includes relation/column identities and ordered PK, UNIQUE and inbound/outbound FK
|
|
4
4
|
// columns and actions, including FKs from outside the kernel schema.
|
|
5
5
|
export async function orgCatalogDrift(db) {
|
|
@@ -30,5 +30,5 @@ WITH catalog AS (
|
|
|
30
30
|
)
|
|
31
31
|
SELECT md5(string_agg(entry, chr(10) ORDER BY entry COLLATE "C")) AS fingerprint FROM catalog
|
|
32
32
|
`.execute(db);
|
|
33
|
-
return rows[0]?.fingerprint === "
|
|
33
|
+
return rows[0]?.fingerprint === "15f8fa57ad75a52e2d08e08ad7742eb9" ? undefined : "schema-drift";
|
|
34
34
|
}
|
package/dist/errors.d.ts
CHANGED
|
@@ -402,6 +402,12 @@ export declare const ERROR_CODES: {
|
|
|
402
402
|
readonly "conversation.queue_item_not_found": 404;
|
|
403
403
|
/** A sub-agent's conversation takes no messages from people (sub-agents spec §6.1). */
|
|
404
404
|
readonly "conversation.read_only": 409;
|
|
405
|
+
/**
|
|
406
|
+
* The conversation is with a local agent (an external conversation, local agents spec Part 2): it
|
|
407
|
+
* does not run here, so Capybara's run controls (queue, compaction, model switch, extension UI
|
|
408
|
+
* actions) do not apply to it.
|
|
409
|
+
*/
|
|
410
|
+
readonly "conversation.external_read_only": 409;
|
|
405
411
|
/**
|
|
406
412
|
* A referenced project file is not there to reference (composer menus §5): the conversation has
|
|
407
413
|
* no device project, the path leaves it, or the device reports no file there;
|
|
@@ -422,6 +428,34 @@ export declare const ERROR_CODES: {
|
|
|
422
428
|
* "not_offered" }]`.
|
|
423
429
|
*/
|
|
424
430
|
readonly "conversation.connector_unavailable": 422;
|
|
431
|
+
/**
|
|
432
|
+
* The conversation target cannot be used now (local agents spec Part 2): its extension does not
|
|
433
|
+
* serve `conversation-target@1` in the org, it does not list the target (or the chosen device),
|
|
434
|
+
* or it did not answer.
|
|
435
|
+
*/
|
|
436
|
+
readonly "conversation.target_unavailable": 409;
|
|
437
|
+
/**
|
|
438
|
+
* A first message mixes the fields of the two kinds: `permission` (or a message model, effort,
|
|
439
|
+
* skill, tokens or files) with a `target`, or a target's `model` / `effort` / `mode` with an
|
|
440
|
+
* `agentId`.
|
|
441
|
+
*/
|
|
442
|
+
readonly "conversation.target_fields": 400;
|
|
443
|
+
/**
|
|
444
|
+
* No device for an external conversation: the chosen one is not among the target's devices, or
|
|
445
|
+
* without a choice neither the default device nor any ready device the target lists fits.
|
|
446
|
+
*/
|
|
447
|
+
readonly "conversation.target_device": 409;
|
|
448
|
+
/** The local agent never started this external conversation (its `start` was dropped). */
|
|
449
|
+
readonly "conversation.external_ended": 409;
|
|
450
|
+
/**
|
|
451
|
+
* A message to an external conversation carries more than its text (tokens, files, a model or
|
|
452
|
+
* effort switch, a skill, a retry); `interrupt` is for external conversations only.
|
|
453
|
+
*/
|
|
454
|
+
readonly "conversation.external_fields": 400;
|
|
455
|
+
/** The external conversation has no request of that id (`external_request`). */
|
|
456
|
+
readonly "conversation.request_not_found": 404;
|
|
457
|
+
/** The request was already answered; the first answer stands. */
|
|
458
|
+
readonly "conversation.request_answered": 409;
|
|
425
459
|
readonly "run.not_active": 409;
|
|
426
460
|
/** A run that is not one of the conversation's (the live draft route, spec 2026-11-07 §3.2). */
|
|
427
461
|
readonly "run.not_found": 404;
|
package/dist/errors.js
CHANGED
|
@@ -402,6 +402,12 @@ export const ERROR_CODES = {
|
|
|
402
402
|
"conversation.queue_item_not_found": 404,
|
|
403
403
|
/** A sub-agent's conversation takes no messages from people (sub-agents spec §6.1). */
|
|
404
404
|
"conversation.read_only": 409,
|
|
405
|
+
/**
|
|
406
|
+
* The conversation is with a local agent (an external conversation, local agents spec Part 2): it
|
|
407
|
+
* does not run here, so Capybara's run controls (queue, compaction, model switch, extension UI
|
|
408
|
+
* actions) do not apply to it.
|
|
409
|
+
*/
|
|
410
|
+
"conversation.external_read_only": 409,
|
|
405
411
|
/**
|
|
406
412
|
* A referenced project file is not there to reference (composer menus §5): the conversation has
|
|
407
413
|
* no device project, the path leaves it, or the device reports no file there;
|
|
@@ -422,6 +428,34 @@ export const ERROR_CODES = {
|
|
|
422
428
|
* "not_offered" }]`.
|
|
423
429
|
*/
|
|
424
430
|
"conversation.connector_unavailable": 422,
|
|
431
|
+
/**
|
|
432
|
+
* The conversation target cannot be used now (local agents spec Part 2): its extension does not
|
|
433
|
+
* serve `conversation-target@1` in the org, it does not list the target (or the chosen device),
|
|
434
|
+
* or it did not answer.
|
|
435
|
+
*/
|
|
436
|
+
"conversation.target_unavailable": 409,
|
|
437
|
+
/**
|
|
438
|
+
* A first message mixes the fields of the two kinds: `permission` (or a message model, effort,
|
|
439
|
+
* skill, tokens or files) with a `target`, or a target's `model` / `effort` / `mode` with an
|
|
440
|
+
* `agentId`.
|
|
441
|
+
*/
|
|
442
|
+
"conversation.target_fields": 400,
|
|
443
|
+
/**
|
|
444
|
+
* No device for an external conversation: the chosen one is not among the target's devices, or
|
|
445
|
+
* without a choice neither the default device nor any ready device the target lists fits.
|
|
446
|
+
*/
|
|
447
|
+
"conversation.target_device": 409,
|
|
448
|
+
/** The local agent never started this external conversation (its `start` was dropped). */
|
|
449
|
+
"conversation.external_ended": 409,
|
|
450
|
+
/**
|
|
451
|
+
* A message to an external conversation carries more than its text (tokens, files, a model or
|
|
452
|
+
* effort switch, a skill, a retry); `interrupt` is for external conversations only.
|
|
453
|
+
*/
|
|
454
|
+
"conversation.external_fields": 400,
|
|
455
|
+
/** The external conversation has no request of that id (`external_request`). */
|
|
456
|
+
"conversation.request_not_found": 404,
|
|
457
|
+
/** The request was already answered; the first answer stands. */
|
|
458
|
+
"conversation.request_answered": 409,
|
|
425
459
|
"run.not_active": 409,
|
|
426
460
|
/** A run that is not one of the conversation's (the live draft route, spec 2026-11-07 §3.2). */
|
|
427
461
|
"run.not_found": 404,
|
package/dist/evals/snapshot.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { normalizeStoredDefinition } from "../agents/definition.js";
|
|
2
|
+
import { agentIdOf } from "../conversations/conversation-agent.js";
|
|
2
3
|
import { ApiError } from "../errors.js";
|
|
3
4
|
import { childRunDefinition } from "../runtime/subagents/definition.js";
|
|
4
5
|
import { storedToolSpec } from "../tools/specs.js";
|
|
@@ -40,7 +41,8 @@ async function conversationRun(db, orgId, conversationId, runId) {
|
|
|
40
41
|
if (!conv || !run) {
|
|
41
42
|
throw new ApiError("conversation.not_found", "Conversation or run not found");
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
+
// the run makes it an agent conversation (an external one has no runs)
|
|
45
|
+
return { conv: { ...conv, agent_id: agentIdOf(conv) }, agentVersion: run.agent_version };
|
|
44
46
|
}
|
|
45
47
|
/**
|
|
46
48
|
* The snapshot of `events`: the agent versions they reference (each `run_started` and the run's
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { type AgentConversationKind } from "../conversations/conversation-agent.js";
|
|
1
2
|
import { EventLog } from "../conversations/event-log.js";
|
|
2
|
-
import type { ConversationKind } from "../db/kernel-schema.js";
|
|
3
3
|
import type { PersonRef } from "../identity/account-avatar.js";
|
|
4
4
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
5
5
|
import { type TrajectoryRun } from "./trajectory.js";
|
|
@@ -23,7 +23,7 @@ export interface TrajectoryDetail {
|
|
|
23
23
|
agentId: string;
|
|
24
24
|
accountId: string;
|
|
25
25
|
title: string | null;
|
|
26
|
-
kind:
|
|
26
|
+
kind: AgentConversationKind;
|
|
27
27
|
/**
|
|
28
28
|
* A sub-agent's conversation (phase C, spec §15.4): the parent conversation and the `agent`
|
|
29
29
|
* call that first dispatched it, for the link back. Visible exactly when the child is (the
|
|
@@ -11,6 +11,7 @@ var TrajectoryService_1;
|
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
12
|
import { sql } from "kysely";
|
|
13
13
|
import { isAgentVisibleTo } from "../agents/agent-lookup.js";
|
|
14
|
+
import { agentIdOf, agentKindOf, } from "../conversations/conversation-agent.js";
|
|
14
15
|
import { EventLog } from "../conversations/event-log.js";
|
|
15
16
|
import { peopleOfEvents } from "../conversations/event-people.js";
|
|
16
17
|
import { ApiError } from "../errors.js";
|
|
@@ -147,7 +148,7 @@ let TrajectoryService = TrajectoryService_1 = class TrajectoryService {
|
|
|
147
148
|
const run = byConv.get(r.id);
|
|
148
149
|
return {
|
|
149
150
|
conversationId: r.id,
|
|
150
|
-
agentId: r
|
|
151
|
+
agentId: agentIdOf(r),
|
|
151
152
|
agentName: r.agent_name ?? "",
|
|
152
153
|
accountId: r.account_id,
|
|
153
154
|
title: r.title,
|
|
@@ -184,16 +185,19 @@ let TrajectoryService = TrajectoryService_1 = class TrajectoryService {
|
|
|
184
185
|
const authAgentId = conv?.kind === "subagent"
|
|
185
186
|
? await this.rootAgentId(orgId, conv.parent_conversation_id)
|
|
186
187
|
: conv?.agent_id;
|
|
187
|
-
|
|
188
|
+
// an external conversation has no agent and no runs: it has no trajectory
|
|
189
|
+
if (!conv || conv.kind === "external" || authAgentId === null || authAgentId === undefined) {
|
|
188
190
|
throw notFound();
|
|
191
|
+
}
|
|
192
|
+
const agentId = agentIdOf(conv);
|
|
189
193
|
if (!(await this.canView(orgId, accountId, authAgentId)))
|
|
190
194
|
throw notFound();
|
|
191
195
|
// an org agent child also needs that agent to be visible to a non-admin viewer, as on the
|
|
192
196
|
// conversation read path (batch 9 ruling; final review m3)
|
|
193
|
-
if (conv.kind === "subagent" &&
|
|
197
|
+
if (conv.kind === "subagent" && agentId !== authAgentId) {
|
|
194
198
|
const role = await this.role(orgId, accountId);
|
|
195
199
|
if ((role === null || !roleAtLeast(role, "admin")) &&
|
|
196
|
-
!(await isAgentVisibleTo(this.db.db,
|
|
200
|
+
!(await isAgentVisibleTo(this.db.db, agentId, accountId))) {
|
|
197
201
|
throw notFound();
|
|
198
202
|
}
|
|
199
203
|
}
|
|
@@ -241,15 +245,15 @@ let TrajectoryService = TrajectoryService_1 = class TrajectoryService {
|
|
|
241
245
|
orgId,
|
|
242
246
|
action: "trajectory.viewed",
|
|
243
247
|
target: conversationId,
|
|
244
|
-
detail: { agentId
|
|
248
|
+
detail: { agentId },
|
|
245
249
|
});
|
|
246
250
|
return {
|
|
247
251
|
conversation: {
|
|
248
252
|
id: conv.id,
|
|
249
|
-
agentId
|
|
253
|
+
agentId,
|
|
250
254
|
accountId: conv.account_id,
|
|
251
255
|
title: conv.title,
|
|
252
|
-
kind: conv.kind,
|
|
256
|
+
kind: agentKindOf(conv.kind),
|
|
253
257
|
...(parent !== undefined && { parent }),
|
|
254
258
|
},
|
|
255
259
|
runs: buildTrajectory(events),
|
|
@@ -32,6 +32,7 @@ import { OrgOverrides } from "./org-overrides.js";
|
|
|
32
32
|
import { PluginGuides } from "./plugin-guides.js";
|
|
33
33
|
import { PluginIcons } from "./plugin-icons.js";
|
|
34
34
|
import { ExtensionPointDefaults } from "./point-defaults.js";
|
|
35
|
+
import { ExtensionPointServingModule } from "./point-serving.js";
|
|
35
36
|
import { ExtensionRegistryModule } from "./registry.js";
|
|
36
37
|
import { SingleProviderGuard } from "./single-provider.js";
|
|
37
38
|
import { ReplicaStatusStore } from "./sources.js";
|
|
@@ -50,6 +51,8 @@ ExtensionsModule = __decorate([
|
|
|
50
51
|
Module({
|
|
51
52
|
imports: [
|
|
52
53
|
ExtensionRegistryModule,
|
|
54
|
+
// one provider's candidacy for a point, shared with the conversation access check
|
|
55
|
+
ExtensionPointServingModule,
|
|
53
56
|
TriggerEventsModule,
|
|
54
57
|
InboxItemsModule,
|
|
55
58
|
SuperAdminLockModule,
|
|
@@ -4,6 +4,8 @@ import type { core } from "zod";
|
|
|
4
4
|
import type { KernelAppOptions } from "../app.js";
|
|
5
5
|
import { TRIGGER_EVENTS_BACKEND } from "../automations/events/token.js";
|
|
6
6
|
import type { KernelConfig } from "../config/schema.js";
|
|
7
|
+
import type { ExternalConversationsBackend } from "../conversations/external/external-conversations.service.js";
|
|
8
|
+
import { EXTERNAL_CONVERSATIONS_BACKEND } from "../conversations/external/token.js";
|
|
7
9
|
import type { BusSubscriber } from "../ctx/bus.js";
|
|
8
10
|
import { type DeviceAccessBackend, type InboxBackend, type PluginReadsBackend, type Route, type TriggersBackend } from "../ctx/create-ctx.js";
|
|
9
11
|
import { ExtensionEffects } from "../ctx/durable-effects.service.js";
|
|
@@ -303,6 +305,8 @@ export declare class ExtensionHost {
|
|
|
303
305
|
* `TriggerEventsService` (`ctx.triggers`, {@link TRIGGER_EVENTS_BACKEND}) and
|
|
304
306
|
* `InboxItemsService` (`ctx.inbox`, {@link INBOX_ITEMS_BACKEND}) and `PluginReadsService`
|
|
305
307
|
* (`ctx.agents`, `ctx.conversations`, `ctx.people`, {@link PLUGIN_READS_BACKEND}) and
|
|
308
|
+
* `ExternalConversationsService` (`ctx.conversations`' external methods,
|
|
309
|
+
* {@link EXTERNAL_CONVERSATIONS_BACKEND}) and
|
|
306
310
|
* `ServiceEvents` (`ctx.devices.serviceEvent`, {@link SERVICE_EVENTS_BACKEND}) likewise.
|
|
307
311
|
*/
|
|
308
312
|
modules?: {
|
|
@@ -324,6 +328,9 @@ export declare class ExtensionHost {
|
|
|
324
328
|
get(token: typeof PLUGIN_READS_BACKEND, opts: {
|
|
325
329
|
strict: false;
|
|
326
330
|
}): PluginReadsBackend;
|
|
331
|
+
get(token: typeof EXTERNAL_CONVERSATIONS_BACKEND, opts: {
|
|
332
|
+
strict: false;
|
|
333
|
+
}): ExternalConversationsBackend;
|
|
327
334
|
},
|
|
328
335
|
/** Tests only: `ctx.net`'s DNS and dispatcher seams (`EXTENSION_NET_SEAMS`). */
|
|
329
336
|
netSeams?: ExtensionNetSeams, dbIdentity?: ExtensionDbIdentity);
|
package/dist/extensions/host.js
CHANGED
|
@@ -16,6 +16,7 @@ import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
|
16
16
|
import { ModuleRef } from "@nestjs/core";
|
|
17
17
|
import { TRIGGER_EVENTS_BACKEND } from "../automations/events/token.js";
|
|
18
18
|
import { changedPaths, configFields, getPath, secretValues, unreachableSecrets, } from "../config/fields.js";
|
|
19
|
+
import { EXTERNAL_CONVERSATIONS_BACKEND } from "../conversations/external/token.js";
|
|
19
20
|
import { pluginSchemaName, queryEnabledPlugins, } from "../ctx/create-ctx.js";
|
|
20
21
|
import { ExtensionEffects } from "../ctx/durable-effects.service.js";
|
|
21
22
|
import { EXTENSION_NET_SEAMS } from "../ctx/net.js";
|
|
@@ -454,6 +455,8 @@ let ExtensionHost = class ExtensionHost {
|
|
|
454
455
|
* `TriggerEventsService` (`ctx.triggers`, {@link TRIGGER_EVENTS_BACKEND}) and
|
|
455
456
|
* `InboxItemsService` (`ctx.inbox`, {@link INBOX_ITEMS_BACKEND}) and `PluginReadsService`
|
|
456
457
|
* (`ctx.agents`, `ctx.conversations`, `ctx.people`, {@link PLUGIN_READS_BACKEND}) and
|
|
458
|
+
* `ExternalConversationsService` (`ctx.conversations`' external methods,
|
|
459
|
+
* {@link EXTERNAL_CONVERSATIONS_BACKEND}) and
|
|
457
460
|
* `ServiceEvents` (`ctx.devices.serviceEvent`, {@link SERVICE_EVENTS_BACKEND}) likewise.
|
|
458
461
|
*/
|
|
459
462
|
modules,
|
|
@@ -542,6 +545,14 @@ let ExtensionHost = class ExtensionHost {
|
|
|
542
545
|
return undefined;
|
|
543
546
|
}
|
|
544
547
|
},
|
|
548
|
+
externalConversations: () => {
|
|
549
|
+
try {
|
|
550
|
+
return modules?.get(EXTERNAL_CONVERSATIONS_BACKEND, { strict: false });
|
|
551
|
+
}
|
|
552
|
+
catch {
|
|
553
|
+
return undefined;
|
|
554
|
+
}
|
|
555
|
+
},
|
|
545
556
|
locks,
|
|
546
557
|
runWorkers: c.roles.includes("worker"),
|
|
547
558
|
log,
|
|
@@ -49,7 +49,9 @@ export interface PermissionItem {
|
|
|
49
49
|
* their accounts and identities), `identity-source@1` decides who can sign in as which account;
|
|
50
50
|
* `context@1` adds text to the model's context in conversations of orgs that enable it (memory
|
|
51
51
|
* plugin spec §6.1); `push-provider@1` receives the title and in-app path of every push
|
|
52
|
-
* notification and the device tokens it delivers to (mobile app spec §9)
|
|
52
|
+
* notification and the device tokens it delivers to (mobile app spec §9);
|
|
53
|
+
* `conversation-target@1` receives the messages people send to their local agents (local agents
|
|
54
|
+
* spec, part 2). A plugin providing any
|
|
53
55
|
* of them has its "provides" group marked sensitive and `sensitive` true in the admin plugin
|
|
54
56
|
* list, for the super admin to approve. Display only: the keys of the permission snapshot do not
|
|
55
57
|
* change.
|
|
@@ -25,7 +25,9 @@ export function reviewHash(set, warnings = []) {
|
|
|
25
25
|
* their accounts and identities), `identity-source@1` decides who can sign in as which account;
|
|
26
26
|
* `context@1` adds text to the model's context in conversations of orgs that enable it (memory
|
|
27
27
|
* plugin spec §6.1); `push-provider@1` receives the title and in-app path of every push
|
|
28
|
-
* notification and the device tokens it delivers to (mobile app spec §9)
|
|
28
|
+
* notification and the device tokens it delivers to (mobile app spec §9);
|
|
29
|
+
* `conversation-target@1` receives the messages people send to their local agents (local agents
|
|
30
|
+
* spec, part 2). A plugin providing any
|
|
29
31
|
* of them has its "provides" group marked sensitive and `sensitive` true in the admin plugin
|
|
30
32
|
* list, for the super admin to approve. Display only: the keys of the permission snapshot do not
|
|
31
33
|
* change.
|
|
@@ -38,6 +40,7 @@ export const SENSITIVE_EXTENSION_POINTS = [
|
|
|
38
40
|
"object-store@1",
|
|
39
41
|
"context@1",
|
|
40
42
|
"push-provider@1",
|
|
43
|
+
"conversation-target@1",
|
|
41
44
|
];
|
|
42
45
|
/** The one item of the "client" group (client extensions spec §5.4). */
|
|
43
46
|
const CLIENT_ITEM = "client code";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
2
2
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
3
3
|
import type { KernelLogger } from "../log.js";
|
|
4
|
-
import { EffectiveConfigs } from "./effective-config.js";
|
|
5
4
|
import { OrgExtensionConfigs } from "./org-config.js";
|
|
5
|
+
import { ExtensionPointServing, type PointProvider } from "./point-serving.js";
|
|
6
6
|
import { ExtensionRegistry } from "./registry.js";
|
|
7
7
|
/**
|
|
8
8
|
* The outcome of {@link ExtensionPointDefaults.resolve}: the provider with its effective deployment
|
|
@@ -17,15 +17,7 @@ export type PointResolution<T> = {
|
|
|
17
17
|
ok: false;
|
|
18
18
|
reason: "none" | "ambiguous";
|
|
19
19
|
};
|
|
20
|
-
|
|
21
|
-
* One provider of a multi-provider extension point for an org ({@link ExtensionPointDefaults.providersFor}),
|
|
22
|
-
* with its effective deployment config for the org, to pass back to it.
|
|
23
|
-
*/
|
|
24
|
-
export interface PointProvider<T> {
|
|
25
|
-
extension: string;
|
|
26
|
-
impl: T;
|
|
27
|
-
config: unknown;
|
|
28
|
-
}
|
|
20
|
+
export type { PointProvider } from "./point-serving.js";
|
|
29
21
|
/** One `org-default` extension point of an org (the admin view). */
|
|
30
22
|
export interface OrgPointDefaultView {
|
|
31
23
|
point: string;
|
|
@@ -50,9 +42,12 @@ export declare class ExtensionPointDefaults {
|
|
|
50
42
|
readonly txHost: TransactionHost;
|
|
51
43
|
private readonly registry;
|
|
52
44
|
private readonly orgConfigs;
|
|
53
|
-
|
|
45
|
+
/** One provider's candidacy (shared with the access checks, below the extensions module). */
|
|
46
|
+
private readonly serving;
|
|
54
47
|
private readonly log;
|
|
55
|
-
constructor(kdb: KernelDb, txHost: TransactionHost, registry: Pick<ExtensionRegistry, "list">, orgConfigs: Pick<OrgExtensionConfigs, "get">,
|
|
48
|
+
constructor(kdb: KernelDb, txHost: TransactionHost, registry: Pick<ExtensionRegistry, "list">, orgConfigs: Pick<OrgExtensionConfigs, "get">,
|
|
49
|
+
/** One provider's candidacy (shared with the access checks, below the extensions module). */
|
|
50
|
+
serving: Pick<ExtensionPointServing, "evaluate" | "serves" | "providerOf">, log: KernelLogger);
|
|
56
51
|
/**
|
|
57
52
|
* The provider of `point` (the name without the major, e.g. `web-search`) for `orgId`, with the
|
|
58
53
|
* effective deployment config for the org to pass back to it. Throws when the point has no
|
|
@@ -94,19 +89,16 @@ export declare class ExtensionPointDefaults {
|
|
|
94
89
|
*/
|
|
95
90
|
private candidates;
|
|
96
91
|
/**
|
|
97
|
-
* Whether the one provider `extension` of `point` evaluates as a candidate in `orgId
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* These are exactly the criteria of {@link providersFor} / {@link resolve}, with only that one
|
|
101
|
-
* provider evaluated. A provider whose status cannot be read counts as not serving (logged).
|
|
92
|
+
* Whether the one provider `extension` of `point` evaluates as a candidate in `orgId`: the
|
|
93
|
+
* criteria of {@link providersFor} / {@link resolve}, with only that provider evaluated
|
|
94
|
+
* ({@link ExtensionPointServing.serves}).
|
|
102
95
|
*/
|
|
103
96
|
serves(orgId: string, point: string, extension: string): Promise<boolean>;
|
|
104
97
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* to `failed`.
|
|
98
|
+
* The one provider `extension` of `point` when it {@link serves} `orgId` now (same criteria),
|
|
99
|
+
* with its implementation and effective config for the org; null otherwise.
|
|
108
100
|
*/
|
|
109
|
-
|
|
101
|
+
providerOf<T>(orgId: string, point: string, extension: string): Promise<PointProvider<T> | null>;
|
|
110
102
|
private choose;
|
|
111
103
|
/** The org's stored defaults, point → extension. */
|
|
112
104
|
private storedDefaults;
|
|
@@ -15,9 +15,9 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
15
15
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
16
16
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
17
17
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
18
|
-
import { EffectiveConfigs } from "./effective-config.js";
|
|
19
18
|
import { enabledExtensionsQuery, isExtensionEnabled } from "./enabled.js";
|
|
20
19
|
import { OrgExtensionConfigs } from "./org-config.js";
|
|
20
|
+
import { ExtensionPointServing } from "./point-serving.js";
|
|
21
21
|
import { ExtensionRegistry } from "./registry.js";
|
|
22
22
|
/** The extension points whose provider each org chooses (`selection: "org-default"`). */
|
|
23
23
|
function selectionPoints() {
|
|
@@ -40,14 +40,16 @@ let ExtensionPointDefaults = class ExtensionPointDefaults {
|
|
|
40
40
|
txHost;
|
|
41
41
|
registry;
|
|
42
42
|
orgConfigs;
|
|
43
|
-
|
|
43
|
+
serving;
|
|
44
44
|
log;
|
|
45
|
-
constructor(kdb, txHost, registry, orgConfigs,
|
|
45
|
+
constructor(kdb, txHost, registry, orgConfigs,
|
|
46
|
+
/** One provider's candidacy (shared with the access checks, below the extensions module). */
|
|
47
|
+
serving, log) {
|
|
46
48
|
this.kdb = kdb;
|
|
47
49
|
this.txHost = txHost;
|
|
48
50
|
this.registry = registry;
|
|
49
51
|
this.orgConfigs = orgConfigs;
|
|
50
|
-
this.
|
|
52
|
+
this.serving = serving;
|
|
51
53
|
this.log = log;
|
|
52
54
|
}
|
|
53
55
|
/**
|
|
@@ -167,7 +169,23 @@ let ExtensionPointDefaults = class ExtensionPointDefaults {
|
|
|
167
169
|
const out = [];
|
|
168
170
|
const failed = new Set();
|
|
169
171
|
for (const [extension, impl] of providers) {
|
|
170
|
-
|
|
172
|
+
let cfg;
|
|
173
|
+
try {
|
|
174
|
+
cfg = await this.orgConfigs.get(orgId, extension);
|
|
175
|
+
}
|
|
176
|
+
catch (err) {
|
|
177
|
+
this.log.warn("extension point provider excluded, cannot read whether it is enabled", {
|
|
178
|
+
orgId,
|
|
179
|
+
point,
|
|
180
|
+
extension,
|
|
181
|
+
err,
|
|
182
|
+
});
|
|
183
|
+
failed.add(extension);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (!cfg?.enabled)
|
|
187
|
+
continue;
|
|
188
|
+
const c = await this.serving.evaluate(orgId, point, extension, impl, failed, this.log);
|
|
171
189
|
if (c)
|
|
172
190
|
out.push(c);
|
|
173
191
|
}
|
|
@@ -175,77 +193,19 @@ let ExtensionPointDefaults = class ExtensionPointDefaults {
|
|
|
175
193
|
return { candidates: out, failed };
|
|
176
194
|
}
|
|
177
195
|
/**
|
|
178
|
-
* Whether the one provider `extension` of `point` evaluates as a candidate in `orgId
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* These are exactly the criteria of {@link providersFor} / {@link resolve}, with only that one
|
|
182
|
-
* provider evaluated. A provider whose status cannot be read counts as not serving (logged).
|
|
196
|
+
* Whether the one provider `extension` of `point` evaluates as a candidate in `orgId`: the
|
|
197
|
+
* criteria of {@link providersFor} / {@link resolve}, with only that provider evaluated
|
|
198
|
+
* ({@link ExtensionPointServing.serves}).
|
|
183
199
|
*/
|
|
184
200
|
async serves(orgId, point, extension) {
|
|
185
|
-
|
|
186
|
-
if (!entry || !(await isExtensionEnabled(this.kdb.db, orgId, extension)))
|
|
187
|
-
return false;
|
|
188
|
-
return (await this.evaluate(orgId, point, extension, entry.impl, new Set())) !== undefined;
|
|
201
|
+
return this.serving.serves(orgId, point, extension, this.log);
|
|
189
202
|
}
|
|
190
203
|
/**
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
* to `failed`.
|
|
204
|
+
* The one provider `extension` of `point` when it {@link serves} `orgId` now (same criteria),
|
|
205
|
+
* with its implementation and effective config for the org; null otherwise.
|
|
194
206
|
*/
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
try {
|
|
198
|
-
cfg = await this.orgConfigs.get(orgId, extension);
|
|
199
|
-
}
|
|
200
|
-
catch (err) {
|
|
201
|
-
this.log.warn("extension point provider excluded, cannot read whether it is enabled", {
|
|
202
|
-
orgId,
|
|
203
|
-
point,
|
|
204
|
-
extension,
|
|
205
|
-
err,
|
|
206
|
-
});
|
|
207
|
-
failed.add(extension);
|
|
208
|
-
return undefined;
|
|
209
|
-
}
|
|
210
|
-
if (!cfg?.enabled)
|
|
211
|
-
return undefined;
|
|
212
|
-
// spec A §6: an org whose effective config is not valid gets no call from this extension
|
|
213
|
-
let effective;
|
|
214
|
-
try {
|
|
215
|
-
effective = await this.effective.get(orgId, extension);
|
|
216
|
-
}
|
|
217
|
-
catch (err) {
|
|
218
|
-
this.log.warn("extension point provider excluded, cannot read its effective config", {
|
|
219
|
-
orgId,
|
|
220
|
-
point,
|
|
221
|
-
extension,
|
|
222
|
-
err,
|
|
223
|
-
});
|
|
224
|
-
failed.add(extension);
|
|
225
|
-
return undefined;
|
|
226
|
-
}
|
|
227
|
-
if (!effective.ok)
|
|
228
|
-
return undefined;
|
|
229
|
-
const configured = impl.configured;
|
|
230
|
-
if (typeof configured === "function") {
|
|
231
|
-
let ok;
|
|
232
|
-
try {
|
|
233
|
-
ok = configured.call(impl, effective.config) !== false;
|
|
234
|
-
}
|
|
235
|
-
catch (err) {
|
|
236
|
-
this.log.warn("extension point provider excluded, configured() threw", {
|
|
237
|
-
orgId,
|
|
238
|
-
point,
|
|
239
|
-
extension,
|
|
240
|
-
err,
|
|
241
|
-
});
|
|
242
|
-
failed.add(extension);
|
|
243
|
-
return undefined;
|
|
244
|
-
}
|
|
245
|
-
if (!ok)
|
|
246
|
-
return undefined;
|
|
247
|
-
}
|
|
248
|
-
return { extension, impl, config: effective.config };
|
|
207
|
+
providerOf(orgId, point, extension) {
|
|
208
|
+
return this.serving.providerOf(orgId, point, extension, this.log);
|
|
249
209
|
}
|
|
250
210
|
async choose(orgId, point, candidates) {
|
|
251
211
|
if (candidates.length < 2)
|
|
@@ -271,7 +231,7 @@ ExtensionPointDefaults = __decorate([
|
|
|
271
231
|
__param(1, Inject(TransactionHost)),
|
|
272
232
|
__param(2, Inject(ExtensionRegistry)),
|
|
273
233
|
__param(3, Inject(OrgExtensionConfigs)),
|
|
274
|
-
__param(4, Inject(
|
|
234
|
+
__param(4, Inject(ExtensionPointServing)),
|
|
275
235
|
__param(5, Inject(KERNEL_LOGGER))
|
|
276
236
|
], ExtensionPointDefaults);
|
|
277
237
|
export { ExtensionPointDefaults };
|