@capybara-hq/kernel 0.1.0-rc.134 → 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/bootstrap.json +1 -1
- 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/config/schema.d.ts +7 -0
- package/dist/config/schema.js +60 -2
- 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/extension-db.d.ts +8 -3
- package/dist/db/extension-db.js +107 -7
- package/dist/db/extension-role-provision.d.ts +9 -0
- package/dist/db/extension-role-provision.js +89 -0
- package/dist/db/extension-schema-transfer.d.ts +2 -1
- package/dist/db/extension-schema-transfer.js +103 -19
- package/dist/db/kernel-schema.d.ts +31 -4
- package/dist/db/migrator.d.ts +2 -0
- package/dist/db/migrator.js +4 -3
- 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/admin-ops.js +17 -1
- package/dist/extensions/extensions.module.js +3 -0
- package/dist/extensions/host.d.ts +9 -1
- package/dist/extensions/host.js +14 -2
- package/dist/extensions/migrate-lock.js +1 -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/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/infra/database/rls-role.d.ts +4 -11
- package/dist/infra/database/rls-role.js +71 -27
- 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.d.ts +2 -0
- package/dist/kernel.js +12 -2
- package/dist/kernel.module.js +4 -0
- package/dist/lifecycle/kernel-lifecycle.js +2 -3
- 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/0226_enable_kernel_rls.sql +30 -0
- package/src/migrations/0227_external_conversations.sql +33 -0
package/bootstrap.json
CHANGED
|
@@ -8,6 +8,7 @@ import { Module } from "@nestjs/common";
|
|
|
8
8
|
import { CatalogModule } from "../catalog/catalog.module.js";
|
|
9
9
|
import { TemplateConnectorsQueueModule } from "../catalog/template-connector-jobs.js";
|
|
10
10
|
import { ChannelsModule } from "../channels/channels.module.js";
|
|
11
|
+
import { ExternalConversationsModule } from "../conversations/external/external-conversations.service.js";
|
|
11
12
|
import { PromptSuggestionsModule } from "../conversations/prompt-suggestions.js";
|
|
12
13
|
import { TitlesModule } from "../conversations/titles.js";
|
|
13
14
|
import { DeviceServiceEventsModule } from "../device-access/service-events.js";
|
|
@@ -75,6 +76,8 @@ AdminModule = __decorate([
|
|
|
75
76
|
TemplateConnectorsQueueModule,
|
|
76
77
|
// the device service events queue the overview counts
|
|
77
78
|
DeviceServiceEventsModule,
|
|
79
|
+
// the external conversation calls queue the overview counts
|
|
80
|
+
ExternalConversationsModule,
|
|
78
81
|
// the price table of the usage aggregate
|
|
79
82
|
ModelsModule,
|
|
80
83
|
],
|
|
@@ -5,7 +5,7 @@ import { type LiveReplica, ReplicaPresence } from "../infra/presence/replica-pre
|
|
|
5
5
|
import type { KernelLogger } from "../log.js";
|
|
6
6
|
import { DeviceProviders } from "../sandbox/providers.js";
|
|
7
7
|
/** The kernel's own queues, in the order the overview lists them (extension queues are not read). */
|
|
8
|
-
export declare const KERNEL_QUEUE_NAMES: 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"];
|
|
8
|
+
export declare const KERNEL_QUEUE_NAMES: 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"];
|
|
9
9
|
/** How long each source's reads may take before the answer marks it unavailable. */
|
|
10
10
|
export declare const HEALTH_READ_TIMEOUT_MS = 3000;
|
|
11
11
|
/** A live replica as the overview shows it. */
|
|
@@ -110,7 +110,7 @@ export declare class AdminHealthService {
|
|
|
110
110
|
private readonly log;
|
|
111
111
|
private readonly providers;
|
|
112
112
|
private readonly queues;
|
|
113
|
-
constructor(presence: Pick<ReplicaPresence, "live">, db: KernelDb, redis: Pick<Redis, "zcount" | "status">, log: Pick<KernelLogger, "warn">, providers: Pick<DeviceProviders, "forDevice">, runs: Queue, subagentRuns: Queue, channels: Queue, maintenance: Queue, toolWatch: Queue, pluginScope: Queue, titles: Queue, suggestions: Queue, usageReport: Queue, evals: Queue, lifecycle: Queue, push: Queue, connectorTools: Queue, templateConnectors: Queue, serviceEvents: Queue);
|
|
113
|
+
constructor(presence: Pick<ReplicaPresence, "live">, db: KernelDb, redis: Pick<Redis, "zcount" | "status">, log: Pick<KernelLogger, "warn">, providers: Pick<DeviceProviders, "forDevice">, runs: Queue, subagentRuns: Queue, channels: Queue, maintenance: Queue, toolWatch: Queue, pluginScope: Queue, titles: Queue, suggestions: Queue, usageReport: Queue, evals: Queue, lifecycle: Queue, push: Queue, connectorTools: Queue, templateConnectors: Queue, serviceEvents: Queue, externalCalls: Queue);
|
|
114
114
|
read(): Promise<AdminHealth>;
|
|
115
115
|
private readRedis;
|
|
116
116
|
private readDb;
|
|
@@ -13,6 +13,7 @@ import { sql } from "kysely";
|
|
|
13
13
|
import { PLUGIN_SCOPE_QUEUE } from "../catalog/scope-sync.js";
|
|
14
14
|
import { TEMPLATE_CONNECTORS_QUEUE } from "../catalog/template-connector-jobs.js";
|
|
15
15
|
import { CHANNEL_QUEUE_NAME } from "../channels/jobs.js";
|
|
16
|
+
import { EXTERNAL_CALLS_QUEUE } from "../conversations/external/external-calls.js";
|
|
16
17
|
import { PROMPT_SUGGESTION_QUEUE } from "../conversations/prompt-suggestions.js";
|
|
17
18
|
import { TITLE_QUEUE } from "../conversations/titles.js";
|
|
18
19
|
import { SERVICE_EVENTS_QUEUE } from "../device-access/service-events.js";
|
|
@@ -47,6 +48,7 @@ export const KERNEL_QUEUE_NAMES = [
|
|
|
47
48
|
CONNECTOR_TOOLS_QUEUE,
|
|
48
49
|
TEMPLATE_CONNECTORS_QUEUE,
|
|
49
50
|
SERVICE_EVENTS_QUEUE,
|
|
51
|
+
EXTERNAL_CALLS_QUEUE,
|
|
50
52
|
];
|
|
51
53
|
/** How long each source's reads may take before the answer marks it unavailable. */
|
|
52
54
|
export const HEALTH_READ_TIMEOUT_MS = 3_000;
|
|
@@ -75,7 +77,7 @@ let AdminHealthService = class AdminHealthService {
|
|
|
75
77
|
log;
|
|
76
78
|
providers;
|
|
77
79
|
queues;
|
|
78
|
-
constructor(presence, db, redis, log, providers, runs, subagentRuns, channels, maintenance, toolWatch, pluginScope, titles, suggestions, usageReport, evals, lifecycle, push, connectorTools, templateConnectors, serviceEvents) {
|
|
80
|
+
constructor(presence, db, redis, log, providers, runs, subagentRuns, channels, maintenance, toolWatch, pluginScope, titles, suggestions, usageReport, evals, lifecycle, push, connectorTools, templateConnectors, serviceEvents, externalCalls) {
|
|
79
81
|
this.presence = presence;
|
|
80
82
|
this.db = db;
|
|
81
83
|
this.redis = redis;
|
|
@@ -98,6 +100,7 @@ let AdminHealthService = class AdminHealthService {
|
|
|
98
100
|
connectorTools,
|
|
99
101
|
templateConnectors,
|
|
100
102
|
serviceEvents,
|
|
103
|
+
externalCalls,
|
|
101
104
|
];
|
|
102
105
|
}
|
|
103
106
|
async read() {
|
|
@@ -311,6 +314,7 @@ AdminHealthService = __decorate([
|
|
|
311
314
|
__param(16, Inject(getQueueToken(PUSH_QUEUE))),
|
|
312
315
|
__param(17, Inject(getQueueToken(CONNECTOR_TOOLS_QUEUE))),
|
|
313
316
|
__param(18, Inject(getQueueToken(TEMPLATE_CONNECTORS_QUEUE))),
|
|
314
|
-
__param(19, Inject(getQueueToken(SERVICE_EVENTS_QUEUE)))
|
|
317
|
+
__param(19, Inject(getQueueToken(SERVICE_EVENTS_QUEUE))),
|
|
318
|
+
__param(20, Inject(getQueueToken(EXTERNAL_CALLS_QUEUE)))
|
|
315
319
|
], AdminHealthService);
|
|
316
320
|
export { AdminHealthService };
|
|
@@ -209,7 +209,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
|
|
|
209
209
|
/** The host versions (an entry's `minKernel` is judged against them). */
|
|
210
210
|
export declare const HOST_VERSIONS: {
|
|
211
211
|
readonly kernel: string;
|
|
212
|
-
readonly sdk: "0.1.0-rc.
|
|
212
|
+
readonly sdk: "0.1.0-rc.100";
|
|
213
213
|
};
|
|
214
214
|
/** Whether this deployment satisfies the entry's `minKernel`. */
|
|
215
215
|
export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
|
package/dist/config/schema.d.ts
CHANGED
|
@@ -69,11 +69,18 @@ export declare const KernelConfigSchema: z.ZodObject<{
|
|
|
69
69
|
url: z.ZodString;
|
|
70
70
|
migrationUrl: z.ZodOptional<z.ZodString>;
|
|
71
71
|
extensionsUrl: z.ZodOptional<z.ZodString>;
|
|
72
|
+
extensionCredentialsDir: z.ZodOptional<z.ZodString>;
|
|
73
|
+
extensionProvisioningUrl: z.ZodOptional<z.ZodString>;
|
|
74
|
+
extensionConnectionLimit: z.ZodDefault<z.ZodNumber>;
|
|
75
|
+
extensionStatementTimeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
76
|
+
extensionIdleTransactionTimeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
77
|
+
extensionTempFileLimitKb: z.ZodDefault<z.ZodNumber>;
|
|
72
78
|
extensionEffectRelayLogin: z.ZodOptional<z.ZodString>;
|
|
73
79
|
extensionPoolMax: z.ZodDefault<z.ZodNumber>;
|
|
74
80
|
poolMax: z.ZodDefault<z.ZodNumber>;
|
|
75
81
|
connectTimeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
76
82
|
idleTimeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
83
|
+
rlsOwnerRole: z.ZodDefault<z.ZodString>;
|
|
77
84
|
rls: z.ZodDefault<z.ZodEnum<{
|
|
78
85
|
enforce: "enforce";
|
|
79
86
|
off: "off";
|
package/dist/config/schema.js
CHANGED
|
@@ -342,7 +342,58 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
342
342
|
.optional()
|
|
343
343
|
.meta(meta({
|
|
344
344
|
secret: true,
|
|
345
|
-
description: "PostgreSQL
|
|
345
|
+
description: "PostgreSQL endpoint and former shared login name for dedicated extension database identities",
|
|
346
|
+
})),
|
|
347
|
+
extensionCredentialsDir: z
|
|
348
|
+
.string()
|
|
349
|
+
.min(1)
|
|
350
|
+
.optional()
|
|
351
|
+
.meta(meta({
|
|
352
|
+
description: "Directory of operator-managed per-extension PostgreSQL password files",
|
|
353
|
+
})),
|
|
354
|
+
extensionProvisioningUrl: z
|
|
355
|
+
.string()
|
|
356
|
+
.min(1)
|
|
357
|
+
.optional()
|
|
358
|
+
.meta(meta({
|
|
359
|
+
secret: true,
|
|
360
|
+
description: "PostgreSQL administration URL for one-shot extension database provisioning only",
|
|
361
|
+
})),
|
|
362
|
+
extensionConnectionLimit: z
|
|
363
|
+
.number()
|
|
364
|
+
.int()
|
|
365
|
+
.min(2)
|
|
366
|
+
.max(1000)
|
|
367
|
+
.default(32)
|
|
368
|
+
.meta(meta({
|
|
369
|
+
description: "Maximum PostgreSQL sessions per extension across replicas, workers, lanes, and migrations",
|
|
370
|
+
})),
|
|
371
|
+
extensionStatementTimeoutMs: z
|
|
372
|
+
.number()
|
|
373
|
+
.int()
|
|
374
|
+
.positive()
|
|
375
|
+
.max(2_147_483_647)
|
|
376
|
+
.default(60_000)
|
|
377
|
+
.meta(meta({
|
|
378
|
+
description: "Default statement timeout for each dedicated extension login in milliseconds",
|
|
379
|
+
})),
|
|
380
|
+
extensionIdleTransactionTimeoutMs: z
|
|
381
|
+
.number()
|
|
382
|
+
.int()
|
|
383
|
+
.positive()
|
|
384
|
+
.max(2_147_483_647)
|
|
385
|
+
.default(30_000)
|
|
386
|
+
.meta(meta({
|
|
387
|
+
description: "Default idle-in-transaction timeout for each dedicated extension login in milliseconds",
|
|
388
|
+
})),
|
|
389
|
+
extensionTempFileLimitKb: z
|
|
390
|
+
.number()
|
|
391
|
+
.int()
|
|
392
|
+
.positive()
|
|
393
|
+
.max(2_147_483_647)
|
|
394
|
+
.default(65_536)
|
|
395
|
+
.meta(meta({
|
|
396
|
+
description: "Temporary file budget for each dedicated extension database session in KiB",
|
|
346
397
|
})),
|
|
347
398
|
extensionEffectRelayLogin: z
|
|
348
399
|
.string()
|
|
@@ -379,11 +430,18 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
379
430
|
.meta(meta({
|
|
380
431
|
description: "How long an idle PostgreSQL connection stays in the pool, in milliseconds",
|
|
381
432
|
})),
|
|
433
|
+
rlsOwnerRole: z
|
|
434
|
+
.string()
|
|
435
|
+
.min(1)
|
|
436
|
+
.default("capybara_owner")
|
|
437
|
+
.meta(meta({
|
|
438
|
+
description: "PostgreSQL role expected to own the kernel schema and org tables in enforce mode",
|
|
439
|
+
})),
|
|
382
440
|
rls: z
|
|
383
441
|
.enum(["off", "scoped", "enforce"])
|
|
384
442
|
.default("off")
|
|
385
443
|
.meta(meta({
|
|
386
|
-
description: "PostgreSQL row-level security mode where off leaves scope unset, scoped sets transaction-local scope while policies admit all rows, and enforce filters by transaction-local scope
|
|
444
|
+
description: "PostgreSQL row-level security mode where off leaves scope unset, scoped sets transaction-local scope while policies admit all rows, and enforce filters by transaction-local scope. Enforce requires the split database roles, the owner migration, and enabled and forced org policies at startup. Both scoped modes require session-capable connections, with ordinary standalone queries sharing a round trip with their scope setup.",
|
|
387
445
|
})),
|
|
388
446
|
})
|
|
389
447
|
.prefault({}),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Expression, type ExpressionBuilder, type SqlBool } from "kysely";
|
|
2
2
|
import type { KernelDatabase } from "../db/kernel-schema.js";
|
|
3
|
+
import { ExtensionPointServing } from "../extensions/point-serving.js";
|
|
3
4
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
4
5
|
/**
|
|
5
6
|
* A sub-agent's conversation is reached through the root of its tree (sub-agents spec §6.1,
|
|
@@ -11,27 +12,34 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
11
12
|
*/
|
|
12
13
|
export declare const parentReachable: (viewerAccountId: string | Expression<string>) => (eb: ExpressionBuilder<KernelDatabase, "conversations">) => import("kysely").ExpressionWrapper<KernelDatabase, "conversations", SqlBool>;
|
|
13
14
|
/**
|
|
14
|
-
* The predicate of {@link ConversationAccess.isAccessible} over the `conversations` table (the
|
|
15
|
+
* The chat predicate of {@link ConversationAccess.isAccessible} over the `conversations` table (the
|
|
15
16
|
* org is the caller's condition): the conversation belongs to the viewer and is not deleted, it is
|
|
16
17
|
* a chat or sub-agent conversation whose tree root is reachable ({@link parentReachable}), the
|
|
17
18
|
* viewer's account is active, and its agent is not deleted and still visible to the viewer
|
|
18
|
-
* (`visibleTo` includes "the org is not deleted, the viewer is still a member").
|
|
19
|
-
*
|
|
19
|
+
* (`visibleTo` includes "the org is not deleted, the viewer is still a member"). An external
|
|
20
|
+
* conversation is not admitted here (it needs its target's serving check). The viewer may be a
|
|
21
|
+
* column of the outer query: the share liveness check (`shares/liveness.ts`) asks it of each
|
|
20
22
|
* share's creator (`sql.ref("file_shares.created_by")`) in the same query.
|
|
21
23
|
*/
|
|
22
24
|
export declare const accessibleTo: (viewer: string | Expression<string>) => (eb: ExpressionBuilder<KernelDatabase, "conversations">) => Expression<SqlBool>;
|
|
23
25
|
/**
|
|
24
26
|
* Whether a person may still see a conversation (one query, no agent view): what the event stream,
|
|
25
27
|
* attachment downloads, file and output reads and the extension UI check. `ConversationsService`
|
|
26
|
-
* delegates to it; it depends on the database
|
|
27
|
-
*
|
|
28
|
+
* delegates to it; it depends on the database and, for an external conversation, on whether its
|
|
29
|
+
* extension serves the org ({@link ExtensionPointServing}, below the extensions module), so the attachments (which the skills and tools use) can check
|
|
30
|
+
* access without the conversations module.
|
|
28
31
|
*/
|
|
29
32
|
export declare class ConversationAccess {
|
|
30
33
|
private readonly db;
|
|
31
|
-
|
|
34
|
+
/** Whether an external conversation's extension serves the org. */
|
|
35
|
+
private readonly serving;
|
|
36
|
+
constructor(db: KernelDb,
|
|
37
|
+
/** Whether an external conversation's extension serves the org. */
|
|
38
|
+
serving: Pick<ExtensionPointServing, "serves">);
|
|
32
39
|
/**
|
|
33
40
|
* The light visibility check (one query, no agent view) used when a long connection (SSE) opens
|
|
34
|
-
* and on its periodic re-check: {@link accessibleTo} for a conversation of this org
|
|
41
|
+
* and on its periodic re-check: {@link accessibleTo} for a conversation of this org, an external
|
|
42
|
+
* conversation's extension checked for serving `conversation-target@1` in the org.
|
|
35
43
|
*/
|
|
36
44
|
isAccessible(orgId: string, conversationId: string, viewerAccountId: string): Promise<boolean>;
|
|
37
45
|
}
|
|
@@ -10,7 +10,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { Inject, Injectable, Module } from "@nestjs/common";
|
|
11
11
|
import { sql } from "kysely";
|
|
12
12
|
import { visibleTo } from "../agents/agent-lookup.js";
|
|
13
|
+
import { ExtensionPointServing, ExtensionPointServingModule } from "../extensions/point-serving.js";
|
|
13
14
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
15
|
+
import { TARGET_POINT } from "./external/external-calls.js";
|
|
14
16
|
/**
|
|
15
17
|
* The root of a sub-agent conversation's tree, as a correlated scalar subquery: walks
|
|
16
18
|
* `parent_conversation_id` up from the conversation's parent through sub-agent conversations of
|
|
@@ -54,12 +56,13 @@ export const parentReachable = (viewerAccountId) => (eb) => eb.or([
|
|
|
54
56
|
.where(visibleTo(viewerAccountId))),
|
|
55
57
|
]);
|
|
56
58
|
/**
|
|
57
|
-
* The predicate of {@link ConversationAccess.isAccessible} over the `conversations` table (the
|
|
59
|
+
* The chat predicate of {@link ConversationAccess.isAccessible} over the `conversations` table (the
|
|
58
60
|
* org is the caller's condition): the conversation belongs to the viewer and is not deleted, it is
|
|
59
61
|
* a chat or sub-agent conversation whose tree root is reachable ({@link parentReachable}), the
|
|
60
62
|
* viewer's account is active, and its agent is not deleted and still visible to the viewer
|
|
61
|
-
* (`visibleTo` includes "the org is not deleted, the viewer is still a member").
|
|
62
|
-
*
|
|
63
|
+
* (`visibleTo` includes "the org is not deleted, the viewer is still a member"). An external
|
|
64
|
+
* conversation is not admitted here (it needs its target's serving check). The viewer may be a
|
|
65
|
+
* column of the outer query: the share liveness check (`shares/liveness.ts`) asks it of each
|
|
63
66
|
* share's creator (`sql.ref("file_shares.created_by")`) in the same query.
|
|
64
67
|
*/
|
|
65
68
|
export const accessibleTo = (viewer) => (eb) => eb.and([
|
|
@@ -80,20 +83,51 @@ export const accessibleTo = (viewer) => (eb) => eb.and([
|
|
|
80
83
|
.where("agents.deleted_at", "is", null)
|
|
81
84
|
.where(visibleTo(viewer))),
|
|
82
85
|
]);
|
|
86
|
+
/**
|
|
87
|
+
* An external conversation (local agents spec Part 2) of the viewer that is not deleted, the
|
|
88
|
+
* viewer's account active and still a member of the conversation's live org (it has no agent to
|
|
89
|
+
* check that through), of any extension: the caller checks that it serves the org.
|
|
90
|
+
*/
|
|
91
|
+
const externalConversationOf = (viewer) => (eb) => eb.and([
|
|
92
|
+
eb("conversations.account_id", "=", viewer),
|
|
93
|
+
eb("conversations.deleted_at", "is", null),
|
|
94
|
+
eb("conversations.kind", "=", "external"),
|
|
95
|
+
eb.exists(eb
|
|
96
|
+
.selectFrom("accounts")
|
|
97
|
+
.select(sql `1`.as("one"))
|
|
98
|
+
.where("accounts.id", "=", viewer)
|
|
99
|
+
.where("accounts.status", "=", "active")),
|
|
100
|
+
eb.exists(eb
|
|
101
|
+
.selectFrom("orgs")
|
|
102
|
+
.select(sql `1`.as("one"))
|
|
103
|
+
.whereRef("orgs.id", "=", "conversations.org_id")
|
|
104
|
+
.where("orgs.deleted_at", "is", null)),
|
|
105
|
+
eb.exists(eb
|
|
106
|
+
.selectFrom("memberships")
|
|
107
|
+
.select(sql `1`.as("one"))
|
|
108
|
+
.whereRef("memberships.org_id", "=", "conversations.org_id")
|
|
109
|
+
.where("memberships.account_id", "=", viewer)),
|
|
110
|
+
]);
|
|
83
111
|
/**
|
|
84
112
|
* Whether a person may still see a conversation (one query, no agent view): what the event stream,
|
|
85
113
|
* attachment downloads, file and output reads and the extension UI check. `ConversationsService`
|
|
86
|
-
* delegates to it; it depends on the database
|
|
87
|
-
*
|
|
114
|
+
* delegates to it; it depends on the database and, for an external conversation, on whether its
|
|
115
|
+
* extension serves the org ({@link ExtensionPointServing}, below the extensions module), so the attachments (which the skills and tools use) can check
|
|
116
|
+
* access without the conversations module.
|
|
88
117
|
*/
|
|
89
118
|
let ConversationAccess = class ConversationAccess {
|
|
90
119
|
db;
|
|
91
|
-
|
|
120
|
+
serving;
|
|
121
|
+
constructor(db,
|
|
122
|
+
/** Whether an external conversation's extension serves the org. */
|
|
123
|
+
serving) {
|
|
92
124
|
this.db = db;
|
|
125
|
+
this.serving = serving;
|
|
93
126
|
}
|
|
94
127
|
/**
|
|
95
128
|
* The light visibility check (one query, no agent view) used when a long connection (SSE) opens
|
|
96
|
-
* and on its periodic re-check: {@link accessibleTo} for a conversation of this org
|
|
129
|
+
* and on its periodic re-check: {@link accessibleTo} for a conversation of this org, an external
|
|
130
|
+
* conversation's extension checked for serving `conversation-target@1` in the org.
|
|
97
131
|
*/
|
|
98
132
|
async isAccessible(orgId, conversationId, viewerAccountId) {
|
|
99
133
|
const row = await this.db
|
|
@@ -103,18 +137,33 @@ let ConversationAccess = class ConversationAccess {
|
|
|
103
137
|
.where("conversations.org_id", "=", orgId)
|
|
104
138
|
.where(accessibleTo(viewerAccountId))
|
|
105
139
|
.executeTakeFirst();
|
|
106
|
-
|
|
140
|
+
if (row !== undefined)
|
|
141
|
+
return true;
|
|
142
|
+
// not a chat or sub-agent conversation the viewer may see: perhaps their external one
|
|
143
|
+
const ext = await this.db
|
|
144
|
+
.selectFrom("conversations")
|
|
145
|
+
.select(sql `conversations.external->>'extension'`.as("extension"))
|
|
146
|
+
.where("conversations.id", "=", conversationId)
|
|
147
|
+
.where("conversations.org_id", "=", orgId)
|
|
148
|
+
.where(externalConversationOf(viewerAccountId))
|
|
149
|
+
.executeTakeFirst();
|
|
150
|
+
return ext !== undefined && (await this.serving.serves(orgId, TARGET_POINT, ext.extension));
|
|
107
151
|
}
|
|
108
152
|
};
|
|
109
153
|
ConversationAccess = __decorate([
|
|
110
154
|
Injectable(),
|
|
111
|
-
__param(0, Inject(KernelDb))
|
|
155
|
+
__param(0, Inject(KernelDb)),
|
|
156
|
+
__param(1, Inject(ExtensionPointServing))
|
|
112
157
|
], ConversationAccess);
|
|
113
158
|
export { ConversationAccess };
|
|
114
159
|
/** The one {@link ConversationAccess} (database only). */
|
|
115
160
|
let ConversationAccessModule = class ConversationAccessModule {
|
|
116
161
|
};
|
|
117
162
|
ConversationAccessModule = __decorate([
|
|
118
|
-
Module({
|
|
163
|
+
Module({
|
|
164
|
+
imports: [ExtensionPointServingModule],
|
|
165
|
+
providers: [ConversationAccess],
|
|
166
|
+
exports: [ConversationAccess],
|
|
167
|
+
})
|
|
119
168
|
], ConversationAccessModule);
|
|
120
169
|
export { ConversationAccessModule };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ConversationKind } from "../db/kernel-schema.js";
|
|
2
|
+
/** The kinds that run an agent: every kind but 'external' (0227). */
|
|
3
|
+
export type AgentConversationKind = Exclude<ConversationKind, "external">;
|
|
4
|
+
/**
|
|
5
|
+
* The agent of a conversation row read by code that reaches only agent conversations: it filters
|
|
6
|
+
* by kind, or it starts from a run, a queue or an approval (an external conversation has none).
|
|
7
|
+
* `conversations_external_shape` makes `agent_id` non-null for every kind but 'external', so a null
|
|
8
|
+
* here is a kernel bug and throws.
|
|
9
|
+
*/
|
|
10
|
+
export declare function agentIdOf(row: {
|
|
11
|
+
agent_id: string | null;
|
|
12
|
+
}): string;
|
|
13
|
+
/** `kind` as an agent conversation's kind; throws for 'external', like {@link agentIdOf}. */
|
|
14
|
+
export declare function agentKindOf(kind: ConversationKind): AgentConversationKind;
|
|
15
|
+
/** {@link agentIdOf} for a conversation view (`ConversationView.agentId`). */
|
|
16
|
+
export declare function agentIdOfView(view: {
|
|
17
|
+
agentId: string | null;
|
|
18
|
+
}): string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The agent of a conversation row read by code that reaches only agent conversations: it filters
|
|
3
|
+
* by kind, or it starts from a run, a queue or an approval (an external conversation has none).
|
|
4
|
+
* `conversations_external_shape` makes `agent_id` non-null for every kind but 'external', so a null
|
|
5
|
+
* here is a kernel bug and throws.
|
|
6
|
+
*/
|
|
7
|
+
export function agentIdOf(row) {
|
|
8
|
+
if (row.agent_id === null) {
|
|
9
|
+
throw new Error("an external conversation reached code that needs a conversation's agent");
|
|
10
|
+
}
|
|
11
|
+
return row.agent_id;
|
|
12
|
+
}
|
|
13
|
+
/** `kind` as an agent conversation's kind; throws for 'external', like {@link agentIdOf}. */
|
|
14
|
+
export function agentKindOf(kind) {
|
|
15
|
+
if (kind === "external") {
|
|
16
|
+
throw new Error("an external conversation reached code that needs a conversation's agent");
|
|
17
|
+
}
|
|
18
|
+
return kind;
|
|
19
|
+
}
|
|
20
|
+
/** {@link agentIdOf} for a conversation view (`ConversationView.agentId`). */
|
|
21
|
+
export function agentIdOfView(view) {
|
|
22
|
+
return agentIdOf({ agent_id: view.agentId });
|
|
23
|
+
}
|
|
@@ -19,7 +19,7 @@ export interface ConversationRefSource {
|
|
|
19
19
|
id: string;
|
|
20
20
|
/** The title at send time; null: untitled. */
|
|
21
21
|
title: string | null;
|
|
22
|
-
/** The name of the conversation's agent. */
|
|
22
|
+
/** The name of the conversation's agent; an external conversation's target label. */
|
|
23
23
|
agentName: string;
|
|
24
24
|
/** When the conversation was last active (its `updated_at`). */
|
|
25
25
|
lastActiveAt: Date;
|
|
@@ -53,6 +53,7 @@ export declare function conversationRefText(src: ConversationRefSource): string;
|
|
|
53
53
|
* no nested blocks), an `assistant_message`'s text blocks (no thinking, tool calls or results).
|
|
54
54
|
* A skill invocation contributes what the person typed (`/name args`), never the rendered skill
|
|
55
55
|
* in `content[0]`; a template sub-agent's skill (or its notice) contributes nothing, like
|
|
56
|
-
* `caseTitle` (evals/sets.service.ts).
|
|
56
|
+
* `caseTitle` (evals/sets.service.ts). An external conversation's `external_user_message` and
|
|
57
|
+
* `external_message` contribute their text (local agents spec Part 2).
|
|
57
58
|
*/
|
|
58
59
|
export declare function refMessageText(type: string, payload: unknown): string;
|
|
@@ -72,9 +72,14 @@ export function conversationRefText(src) {
|
|
|
72
72
|
* no nested blocks), an `assistant_message`'s text blocks (no thinking, tool calls or results).
|
|
73
73
|
* A skill invocation contributes what the person typed (`/name args`), never the rendered skill
|
|
74
74
|
* in `content[0]`; a template sub-agent's skill (or its notice) contributes nothing, like
|
|
75
|
-
* `caseTitle` (evals/sets.service.ts).
|
|
75
|
+
* `caseTitle` (evals/sets.service.ts). An external conversation's `external_user_message` and
|
|
76
|
+
* `external_message` contribute their text (local agents spec Part 2).
|
|
76
77
|
*/
|
|
77
78
|
export function refMessageText(type, payload) {
|
|
79
|
+
if (type === "external_user_message" || type === "external_message") {
|
|
80
|
+
const text = payload?.text;
|
|
81
|
+
return typeof text === "string" ? text.trim() : "";
|
|
82
|
+
}
|
|
78
83
|
const content = payload?.content;
|
|
79
84
|
if (!Array.isArray(content))
|
|
80
85
|
return "";
|
|
@@ -11,6 +11,8 @@ import { CompactBody, EventsQuery, FilesQuery, IdParams, ListQuery, PatchBody, S
|
|
|
11
11
|
import { type ConversationGroup, type ConversationListRow, ConversationsService, type ConversationView, type SubagentView, type UsageTotals } from "./conversations.service.js";
|
|
12
12
|
import { ConversationDeviceStatus } from "./device-status.js";
|
|
13
13
|
import type { ConversationEvent } from "./events.js";
|
|
14
|
+
import { ExternalAnswerBody, ExternalRequestParams } from "./external/external.schemas.js";
|
|
15
|
+
import { ExternalConversationsService } from "./external/external-conversations.service.js";
|
|
14
16
|
import { ConversationFiles, type FileOutput } from "./files.js";
|
|
15
17
|
import { ConversationOutputs, type OutputPage } from "./outputs-read.js";
|
|
16
18
|
import type { QueueItem, QueuePauseReason } from "./queue.js";
|
|
@@ -71,6 +73,11 @@ export declare const MessageTokenSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
71
73
|
type: z.ZodLiteral<"conversation">;
|
|
72
74
|
id: z.ZodString;
|
|
73
75
|
}, z.core.$strict>], "type">;
|
|
76
|
+
/**
|
|
77
|
+
* `POST …/messages`. On an external conversation only `text` (with `clientMessageId` and the
|
|
78
|
+
* browser context) and `interrupt` (stop the target's current turn first) are taken; the other
|
|
79
|
+
* fields are `conversation.external_fields`, and so is `interrupt` on any other conversation.
|
|
80
|
+
*/
|
|
74
81
|
declare const MessageBody: z.ZodObject<{
|
|
75
82
|
text: z.ZodString;
|
|
76
83
|
clientMessageId: z.ZodOptional<z.ZodString>;
|
|
@@ -112,6 +119,7 @@ declare const MessageBody: z.ZodObject<{
|
|
|
112
119
|
en: "en";
|
|
113
120
|
zh: "zh";
|
|
114
121
|
}>>;
|
|
122
|
+
interrupt: z.ZodOptional<z.ZodBoolean>;
|
|
115
123
|
}, z.core.$strict>;
|
|
116
124
|
/**
|
|
117
125
|
* `POST /conversations`: `message` creates the conversation with its first message (create on
|
|
@@ -184,7 +192,8 @@ export declare class ConversationsController {
|
|
|
184
192
|
private readonly toolInfo;
|
|
185
193
|
private readonly queue;
|
|
186
194
|
private readonly files;
|
|
187
|
-
|
|
195
|
+
private readonly external;
|
|
196
|
+
constructor(conversations: ConversationsService, outputs: ConversationOutputs, artifacts: ConversationArtifacts, deviceStatus: ConversationDeviceStatus, toolInfo: ConversationToolInfo, queue: ConversationQueue, files: ConversationFiles, external: Pick<ExternalConversationsService, "find" | "send" | "stop" | "answer">);
|
|
188
197
|
/**
|
|
189
198
|
* 201 when created; 200 when `message.clientMessageId` repeats an earlier first send. With a
|
|
190
199
|
* message the answer has `event` (the `user_message`) and `events`: every event the first send
|
|
@@ -205,7 +214,8 @@ export declare class ConversationsController {
|
|
|
205
214
|
/** Soft delete (owner only): stops an active run and hides the conversation everywhere. */
|
|
206
215
|
remove(principal: Principal, org: OrgContext, { id }: z.infer<typeof IdParams>): Promise<void>;
|
|
207
216
|
/**
|
|
208
|
-
* My conversations, most recently updated first, each with its agent
|
|
217
|
+
* My conversations, most recently updated first, each with its agent (null for an external
|
|
218
|
+
* conversation; `target` keeps one target's, local agents spec Part 2): `next` is the next page's
|
|
209
219
|
* cursor (passed back as `after`), null when there are no more; `total` counts every match of
|
|
210
220
|
* the filters and comes only when asked (`withTotal=true`) on the first page (no `after`).
|
|
211
221
|
*/
|
|
@@ -215,8 +225,9 @@ export declare class ConversationsController {
|
|
|
215
225
|
total?: number;
|
|
216
226
|
}>;
|
|
217
227
|
/**
|
|
218
|
-
* My conversations grouped by agent, for the sidebar: groups by
|
|
219
|
-
* newest conversations each with `more`; `next` is the last group's
|
|
228
|
+
* My conversations grouped by agent, and my external ones by target, for the sidebar: groups by
|
|
229
|
+
* latest activity, `perGroup` newest conversations each with `more`; `next` is the last group's
|
|
230
|
+
* key (passed back as
|
|
220
231
|
* `after`), null when there are no more groups. Declared before `:id` so it is not captured.
|
|
221
232
|
*/
|
|
222
233
|
groups(principal: Principal, org: OrgContext, q: z.infer<typeof GroupsQuery>): Promise<{
|
|
@@ -317,6 +328,8 @@ export declare class ConversationsController {
|
|
|
317
328
|
postMessage(principal: Principal, org: OrgContext, id: string, body: z.infer<typeof MessageBody>, reply: FastifyReply): Promise<{
|
|
318
329
|
event: ConversationEvent;
|
|
319
330
|
}>;
|
|
331
|
+
/** {@link postMessage} on a conversation Capybara runs. */
|
|
332
|
+
private postChatMessage;
|
|
320
333
|
/**
|
|
321
334
|
* Queued messages (owner only): `paused` after a run failed or was stopped with items queued, or
|
|
322
335
|
* the head item could not be sent; `pauseReason` says which (absent when not recorded).
|
|
@@ -344,9 +357,19 @@ export declare class ConversationsController {
|
|
|
344
357
|
* ran). On a sub-agent's conversation (the root's owner, at any depth) the
|
|
345
358
|
* sub-agent stops with every sub-agent below it, and `runId` is the sub-agent's latest run,
|
|
346
359
|
* which may already be finished when only its descendants were working (agent map spec §6).
|
|
360
|
+
* On an external conversation the target's `stop` is owed and `runId` is null.
|
|
347
361
|
*/
|
|
348
362
|
abort(principal: Principal, org: OrgContext, id: string): Promise<{
|
|
349
|
-
runId: string;
|
|
363
|
+
runId: string | null;
|
|
364
|
+
}>;
|
|
365
|
+
/**
|
|
366
|
+
* The person's answer to a local agent's request (`external_request`, local agents spec Part 2,
|
|
367
|
+
* call 8): 202 `{ event }`, the `external_request_answered` written once (the first answer wins;
|
|
368
|
+
* a second → 409 `conversation.request_answered`) and the target's `answer` owed. An unknown
|
|
369
|
+
* request → 404 `conversation.request_not_found`; an option it does not offer → 400.
|
|
370
|
+
*/
|
|
371
|
+
answerExternal(principal: Principal, org: OrgContext, params: z.infer<typeof ExternalRequestParams>, body: z.infer<typeof ExternalAnswerBody>): Promise<{
|
|
372
|
+
event: ConversationEvent;
|
|
350
373
|
}>;
|
|
351
374
|
/**
|
|
352
375
|
* Manual compaction (context compaction spec §4.7): starts a compact run that summarizes the
|