@capybara-hq/kernel 0.1.0-rc.131 → 0.1.0-rc.133
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 +5 -5
- package/dist/admin/admin.module.js +3 -0
- package/dist/admin/admin.schemas.d.ts +4 -0
- package/dist/admin/health.service.d.ts +2 -2
- package/dist/admin/health.service.js +6 -2
- package/dist/admin/setup.service.js +6 -1
- package/dist/agents/agents.controller.js +3 -2
- package/dist/agents/agents.service.d.ts +2 -0
- package/dist/agents/agents.service.js +7 -0
- package/dist/catalog/catalog.service.d.ts +2 -0
- package/dist/catalog/catalog.service.js +28 -5
- package/dist/catalog/marketplace-fetch.d.ts +2 -0
- package/dist/catalog/marketplace-fetch.js +15 -0
- package/dist/catalog/marketplaces.service.d.ts +4 -4
- package/dist/catalog/marketplaces.service.js +3 -2
- package/dist/catalog/owned-items.d.ts +2 -0
- package/dist/catalog/owned-items.js +30 -31
- package/dist/catalog/ownership.js +40 -38
- package/dist/catalog/plugin-import.d.ts +6 -5
- package/dist/catalog/plugin-import.js +69 -16
- package/dist/catalog/plugin-upgrade.d.ts +8 -0
- package/dist/catalog/plugin-upgrade.js +95 -7
- package/dist/catalog/publisher-policy.d.ts +9 -0
- package/dist/catalog/publisher-policy.js +12 -0
- package/dist/catalog/unshare.js +66 -58
- package/dist/client/client-access.service.js +5 -3
- package/dist/config/schema.d.ts +1 -0
- package/dist/config/schema.js +9 -1
- package/dist/conversations/conversations.controller.js +4 -14
- package/dist/conversations/conversations.service.d.ts +14 -0
- package/dist/conversations/conversations.service.js +20 -2
- package/dist/ctx/create-ctx.d.ts +14 -4
- package/dist/ctx/create-ctx.js +131 -59
- package/dist/ctx/queue.js +7 -4
- package/dist/db/extension-db.d.ts +30 -0
- package/dist/db/extension-db.js +91 -0
- package/dist/db/extension-rls-predicate.d.ts +1 -0
- package/dist/db/extension-rls-predicate.js +8 -0
- package/dist/db/extension-schema-transfer.d.ts +6 -0
- package/dist/db/extension-schema-transfer.js +141 -0
- package/dist/db/kernel-schema.d.ts +50 -4
- package/dist/db/migrator.d.ts +6 -0
- package/dist/db/migrator.js +35 -7
- package/dist/db/pool.d.ts +6 -2
- package/dist/db/pool.js +37 -2
- package/dist/db/sql-statements.d.ts +3 -0
- package/dist/db/sql-statements.js +15 -5
- package/dist/device-access/device-access.module.js +12 -2
- package/dist/device-access/device-access.service.d.ts +30 -2
- package/dist/device-access/device-access.service.js +38 -4
- package/dist/device-access/host-gate.d.ts +45 -0
- package/dist/device-access/host-gate.js +92 -0
- package/dist/device-access/host-service-stop-sweep.d.ts +33 -0
- package/dist/device-access/host-service-stop-sweep.js +112 -0
- package/dist/device-access/host-service-stop.d.ts +78 -0
- package/dist/device-access/host-service-stop.js +144 -0
- package/dist/device-access/host-services.d.ts +211 -0
- package/dist/device-access/host-services.js +803 -0
- package/dist/device-access/person-handles.d.ts +10 -0
- package/dist/device-access/person-handles.js +25 -0
- package/dist/device-access/service-events.d.ts +199 -0
- package/dist/device-access/service-events.js +704 -0
- package/dist/device-access/token.d.ts +5 -0
- package/dist/device-access/token.js +5 -0
- package/dist/devices/devices.service.js +3 -0
- package/dist/dial-in/access.d.ts +5 -5
- package/dist/dial-in/access.js +19 -12
- package/dist/dial-in/gateway.js +6 -2
- package/dist/dial-in/machines.d.ts +9 -2
- package/dist/dial-in/machines.js +27 -4
- package/dist/erasure/device-cleanup.js +12 -0
- package/dist/erasure/org-catalog.js +2 -2
- package/dist/erasure/org-rules.js +9 -0
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +2 -0
- package/dist/extensions/admin-ops.d.ts +3 -1
- package/dist/extensions/admin-ops.js +19 -9
- package/dist/extensions/deployed-snapshots.d.ts +4 -1
- package/dist/extensions/deployed-snapshots.js +7 -2
- package/dist/extensions/extensions.module.js +3 -0
- package/dist/extensions/host.d.ts +11 -3
- package/dist/extensions/host.js +40 -8
- package/dist/extensions/instance.d.ts +6 -0
- package/dist/extensions/instance.js +7 -1
- package/dist/extensions/ledger.d.ts +1 -1
- package/dist/extensions/lifecycle-hooks.js +3 -3
- package/dist/extensions/migrate-lock.d.ts +4 -1
- package/dist/extensions/migrate-lock.js +19 -2
- package/dist/extensions/org-config.js +6 -1
- package/dist/extensions/permission-set.d.ts +7 -0
- package/dist/extensions/permission-set.js +10 -0
- package/dist/extensions/permission-view.d.ts +1 -1
- package/dist/extensions/permission-view.js +10 -1
- package/dist/git/tickets.js +32 -27
- package/dist/http/app.js +5 -3
- package/dist/identity/accounts.d.ts +6 -1
- package/dist/identity/accounts.js +11 -2
- package/dist/identity/api-tokens.js +7 -6
- package/dist/identity/settings.d.ts +9 -1
- package/dist/identity/settings.js +16 -1
- package/dist/inbox/org-notices.js +3 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/infra/database/scoped-dialect.d.ts +3 -2
- package/dist/infra/database/scoped-dialect.js +260 -72
- package/dist/infra/database/startup-activation-transaction.d.ts +2 -0
- package/dist/infra/database/startup-activation-transaction.js +3 -2
- package/dist/infra/outbox/registry.d.ts +28 -14
- package/dist/infra/outbox/registry.js +30 -15
- package/dist/infra/queue/queue-names.d.ts +1 -1
- package/dist/infra/queue/queue-names.js +1 -0
- package/dist/infra/queue/run-job.d.ts +4 -1
- package/dist/infra/queue/run-job.js +10 -2
- package/dist/kernel.js +4 -0
- package/dist/kernel.module.js +3 -0
- package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +26 -21
- package/dist/orgs/offboarding.js +18 -9
- package/dist/orgs/settings.service.js +3 -0
- package/dist/packages/npm-publish-keys.json +27 -0
- package/dist/packages/official-publisher.d.ts +19 -0
- package/dist/packages/official-publisher.js +152 -0
- package/dist/packages/provenance.d.ts +7 -0
- package/dist/packages/provenance.js +22 -19
- package/dist/packages/sigstore-trusted-root.json +126 -0
- package/dist/platform/ops/admin.ops.js +2 -1
- package/dist/platform/ops/orgs.ops.js +1 -0
- package/dist/roles/worker-role.d.ts +6 -3
- package/dist/roles/worker-role.js +12 -4
- package/dist/roles/worker.module.js +7 -6
- package/dist/runtime/maintenance.d.ts +5 -4
- package/dist/runtime/maintenance.js +16 -13
- package/dist/sandbox/device-reports.d.ts +4 -4
- package/dist/sandbox/device-reports.js +40 -30
- package/dist/sandbox/device-services.d.ts +2 -1
- package/dist/sandbox/device-services.js +5 -1
- package/dist/sandbox/permission-ceiling-writes.d.ts +8 -0
- package/dist/sandbox/permission-ceiling-writes.js +21 -0
- package/dist/sandbox/permission-config-publication.js +5 -1
- package/dist/themes/theme-state.js +24 -13
- package/dist/tools/call-scope.d.ts +6 -0
- package/dist/tools/call-scope.js +22 -0
- package/dist/tools/registry.js +20 -2
- package/dist/ui/views.js +36 -8
- package/package.json +9 -4
- package/src/migrations/0219_event_org_constraint_check.sql +29 -0
- package/src/migrations/0220_require_event_org.sql +18 -0
- package/src/migrations/0221_drop_connector_declaration_policy.sql +2 -0
- package/src/migrations/0222_device_host_services.sql +27 -0
- package/src/migrations/0223_device_service_events.sql +54 -0
- package/src/migrations/0224_cache_conversation_rls_settings.sql +33 -0
- package/dist/conversations/event-org-backfill.d.ts +0 -111
- package/dist/conversations/event-org-backfill.js +0 -264
- package/dist/conversations/event-org-backfill.module.d.ts +0 -3
- package/dist/conversations/event-org-backfill.module.js +0 -18
package/dist/config/schema.js
CHANGED
|
@@ -344,6 +344,14 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
344
344
|
secret: true,
|
|
345
345
|
description: "PostgreSQL connection URL for the shared extension login",
|
|
346
346
|
})),
|
|
347
|
+
extensionPoolMax: z
|
|
348
|
+
.number()
|
|
349
|
+
.int()
|
|
350
|
+
.positive()
|
|
351
|
+
.default(2)
|
|
352
|
+
.meta(meta({
|
|
353
|
+
description: "Maximum PostgreSQL connections per active extension instance with a separate login",
|
|
354
|
+
})),
|
|
347
355
|
poolMax: z
|
|
348
356
|
.number()
|
|
349
357
|
.int()
|
|
@@ -368,7 +376,7 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
368
376
|
.enum(["off", "scoped", "enforce"])
|
|
369
377
|
.default("off")
|
|
370
378
|
.meta(meta({
|
|
371
|
-
description: "
|
|
379
|
+
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 on tables with RLS enabled when the runtime login is subject to the policies. Both scoped modes require session-capable connections, with ordinary standalone queries sharing a round trip with their scope setup.",
|
|
372
380
|
})),
|
|
373
381
|
})
|
|
374
382
|
.prefault({}),
|
|
@@ -351,13 +351,7 @@ let ConversationsController = class ConversationsController {
|
|
|
351
351
|
}
|
|
352
352
|
async get(principal, org, id) {
|
|
353
353
|
const p = requireUser(principal);
|
|
354
|
-
|
|
355
|
-
return {
|
|
356
|
-
conversation: {
|
|
357
|
-
...conversation,
|
|
358
|
-
owner: await this.conversations.person(conversation.accountId),
|
|
359
|
-
},
|
|
360
|
-
};
|
|
354
|
+
return { conversation: await this.conversations.getWithOwner(org.orgId, id, p.account.id) };
|
|
361
355
|
}
|
|
362
356
|
/**
|
|
363
357
|
* Events in ascending seq. `after`: those after it (at most `limit`; the client passes the last
|
|
@@ -366,13 +360,9 @@ let ConversationsController = class ConversationsController {
|
|
|
366
360
|
*/
|
|
367
361
|
async events(principal, org, id, q) {
|
|
368
362
|
const p = requireUser(principal);
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
return { ...page, people: await this.conversations.eventPeople(page.events) };
|
|
373
|
-
}
|
|
374
|
-
const events = await this.conversations.listEvents(org.orgId, id, p.account.id, q.after ?? 0, q.limit);
|
|
375
|
-
return { events, people: await this.conversations.eventPeople(events) };
|
|
363
|
+
return this.conversations.listEventsWithPeople(org.orgId, id, p.account.id, q.before !== undefined
|
|
364
|
+
? { before: q.before === "end" ? null : q.before, limit: q.limit }
|
|
365
|
+
: { after: q.after ?? 0, limit: q.limit });
|
|
376
366
|
}
|
|
377
367
|
/**
|
|
378
368
|
* The conversation's sub-agents, newest first (sub-agents spec §14.3): `{ subagents, next }`,
|
|
@@ -542,6 +542,9 @@ export declare class ConversationsService {
|
|
|
542
542
|
private treeExpired;
|
|
543
543
|
/** 读会话:非所有者、或 agent 已对所有者不可用 → `conversation.not_found`。 */
|
|
544
544
|
get(orgId: string, conversationId: string, viewerAccountId: string): Promise<ConversationView>;
|
|
545
|
+
getWithOwner(orgId: string, conversationId: string, viewerAccountId: string): Promise<ConversationView & {
|
|
546
|
+
owner: PersonRef | null;
|
|
547
|
+
}>;
|
|
545
548
|
/**
|
|
546
549
|
* {@link get} for a change made by a person (a message, rename, queue, model switch): a
|
|
547
550
|
* sub-agent's conversation is read-only (sub-agents spec §6.1) → `conversation.read_only`.
|
|
@@ -648,6 +651,17 @@ export declare class ConversationsService {
|
|
|
648
651
|
events: ConversationEvent[];
|
|
649
652
|
turnsBefore: number;
|
|
650
653
|
}>;
|
|
654
|
+
listEventsWithPeople(orgId: string, conversationId: string, viewerAccountId: string, page: {
|
|
655
|
+
before: number | null;
|
|
656
|
+
limit: number;
|
|
657
|
+
} | {
|
|
658
|
+
after: number;
|
|
659
|
+
limit: number;
|
|
660
|
+
}): Promise<{
|
|
661
|
+
events: ConversationEvent[];
|
|
662
|
+
turnsBefore?: number;
|
|
663
|
+
people: Record<string, PersonRef>;
|
|
664
|
+
}>;
|
|
651
665
|
/**
|
|
652
666
|
* Appends a user message; a repeated send with the same `clientMessageId` returns the same
|
|
653
667
|
* event. After the write it calls `ensureRun`: with no run in progress it enqueues one; during
|
|
@@ -778,6 +778,10 @@ let ConversationsService = class ConversationsService {
|
|
|
778
778
|
const { kind: _kind, ...row } = await this.readable(orgId, conversationId, viewerAccountId);
|
|
779
779
|
return toView(row);
|
|
780
780
|
}
|
|
781
|
+
async getWithOwner(orgId, conversationId, viewerAccountId) {
|
|
782
|
+
const conversation = await this.get(orgId, conversationId, viewerAccountId);
|
|
783
|
+
return { ...conversation, owner: await this.person(conversation.accountId) };
|
|
784
|
+
}
|
|
781
785
|
/**
|
|
782
786
|
* {@link get} for a change made by a person (a message, rename, queue, model switch): a
|
|
783
787
|
* sub-agent's conversation is read-only (sub-agents spec §6.1) → `conversation.read_only`.
|
|
@@ -837,8 +841,8 @@ let ConversationsService = class ConversationsService {
|
|
|
837
841
|
.$if(opts.total === true, (qb) => qb.select(sql `count(*) OVER ()`.as("total_count")))
|
|
838
842
|
.where("org_id", "=", orgId)
|
|
839
843
|
.where("account_id", "=", accountId)
|
|
840
|
-
//
|
|
841
|
-
.where("kind", "=", "chat")
|
|
844
|
+
// Keep the fixed kind literal so generic plans can use the partial chat index.
|
|
845
|
+
.where("kind", "=", sql.lit("chat"))
|
|
842
846
|
.where("deleted_at", "is", null)
|
|
843
847
|
.where("archived_at", opts.archived === true ? "is not" : "is", null)
|
|
844
848
|
.where((eb) => eb.exists(eb
|
|
@@ -1151,6 +1155,14 @@ let ConversationsService = class ConversationsService {
|
|
|
1151
1155
|
await this.get(orgId, conversationId, viewerAccountId);
|
|
1152
1156
|
return this.eventLog.readTurnPageBefore(conversationId, beforeSeq, limit, EVENTS_TURN_EXTEND);
|
|
1153
1157
|
}
|
|
1158
|
+
async listEventsWithPeople(orgId, conversationId, viewerAccountId, page) {
|
|
1159
|
+
const result = "before" in page
|
|
1160
|
+
? await this.listEventsBefore(orgId, conversationId, viewerAccountId, page.before, page.limit)
|
|
1161
|
+
: {
|
|
1162
|
+
events: await this.listEvents(orgId, conversationId, viewerAccountId, page.after, page.limit),
|
|
1163
|
+
};
|
|
1164
|
+
return { ...result, people: await this.eventPeople(result.events) };
|
|
1165
|
+
}
|
|
1154
1166
|
/**
|
|
1155
1167
|
* Appends a user message; a repeated send with the same `clientMessageId` returns the same
|
|
1156
1168
|
* event. After the write it calls `ensureRun`: with no run in progress it enqueues one; during
|
|
@@ -1976,6 +1988,12 @@ __decorate([
|
|
|
1976
1988
|
__decorate([
|
|
1977
1989
|
Transactional()
|
|
1978
1990
|
], ConversationsService.prototype, "markDeleted", null);
|
|
1991
|
+
__decorate([
|
|
1992
|
+
Transactional({ accessMode: "read only" })
|
|
1993
|
+
], ConversationsService.prototype, "getWithOwner", null);
|
|
1994
|
+
__decorate([
|
|
1995
|
+
Transactional({ accessMode: "read only" })
|
|
1996
|
+
], ConversationsService.prototype, "listEventsWithPeople", null);
|
|
1979
1997
|
__decorate([
|
|
1980
1998
|
Transactional({ propagation: "requires_new" })
|
|
1981
1999
|
], ConversationsService.prototype, "postIn", null);
|
package/dist/ctx/create-ctx.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ import { type EmbedClaims, type ExtensionContext, type ExtensionManifest, type E
|
|
|
2
2
|
import type { Redis } from "ioredis";
|
|
3
3
|
import { Kysely } from "kysely";
|
|
4
4
|
import type { TriggerEventsService } from "../automations/events/trigger-events.service.js";
|
|
5
|
+
import { pluginSchemaName } from "../db/extension-db.js";
|
|
5
6
|
import type { DeviceAccessService } from "../device-access/device-access.service.js";
|
|
7
|
+
import type { ServiceEventHandler, ServiceEventsBackend } from "../device-access/service-events.js";
|
|
6
8
|
import type { DialInAccess } from "../dial-in/access.js";
|
|
7
9
|
import { type RegisteredHook } from "../extensions/hooks.js";
|
|
8
10
|
import { RegistrationLedger } from "../extensions/ledger.js";
|
|
@@ -20,6 +22,7 @@ import { type UiActionHandler, type UiQueryHandler, type UiRender } from "../ui/
|
|
|
20
22
|
import { type BusSubscriber } from "./bus.js";
|
|
21
23
|
import { type ExtensionNetServices } from "./net.js";
|
|
22
24
|
import { type Keyring } from "./secrets.js";
|
|
25
|
+
export { pluginSchemaName };
|
|
23
26
|
/** 内核提供给插件宿主的共享依赖。 */
|
|
24
27
|
export interface KernelDeps {
|
|
25
28
|
db: Kysely<any>;
|
|
@@ -66,7 +69,7 @@ export interface KernelDeps {
|
|
|
66
69
|
* served by the calling extension. Absent (a ctx built alone in a test): `ctx.dialIn` calls
|
|
67
70
|
* reject.
|
|
68
71
|
*/
|
|
69
|
-
dialIn?: Pick<DialInAccess, "
|
|
72
|
+
dialIn?: Pick<DialInAccess, "servedOrg" | "request" | "online" | "capacity" | "stop" | "openStream">;
|
|
70
73
|
/**
|
|
71
74
|
* What `ctx.devices` is built from (`DeviceReports`): `changed` reads a device's report again
|
|
72
75
|
* from the calling provider and refuses (`not-served`) a device bound to another one. Absent
|
|
@@ -79,6 +82,12 @@ export interface KernelDeps {
|
|
|
79
82
|
* a test, the CLI): `ctx.deviceAccess` calls are refused.
|
|
80
83
|
*/
|
|
81
84
|
deviceAccess?: () => DeviceAccessBackend | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* What `ctx.devices.serviceEvent` calls through (`ServiceEvents`), found at the time of use like
|
|
87
|
+
* `deviceAccess`. Absent, or resolving to undefined (a ctx built alone in a test, the CLI):
|
|
88
|
+
* `ctx.devices.serviceEvent` rejects.
|
|
89
|
+
*/
|
|
90
|
+
serviceEvents?: () => ServiceEventsBackend | undefined;
|
|
82
91
|
/**
|
|
83
92
|
* What `ctx.triggers` calls through (`TriggerEventsService`), found at the time of use like
|
|
84
93
|
* `deviceAccess`. Absent, or resolving to undefined (a ctx built alone in a test, the CLI):
|
|
@@ -103,7 +112,7 @@ export interface KernelDeps {
|
|
|
103
112
|
};
|
|
104
113
|
}
|
|
105
114
|
/** What `ctx.deviceAccess` calls through (`DeviceAccessService`). */
|
|
106
|
-
export type DeviceAccessBackend = Pick<DeviceAccessService, "ensureService" | "request" | "reportBlockedHosts" | "requestSiteAccess" | "siteGrants" | "revokeSiteGrant" | "streamTicket" | "addNetworkHosts" | "answerHandoff" | "grantLoopbackPort" | "revokeLoopbackPort" | "loopbackPorts">;
|
|
115
|
+
export type DeviceAccessBackend = Pick<DeviceAccessService, "ensureService" | "request" | "reportBlockedHosts" | "requestSiteAccess" | "siteGrants" | "revokeSiteGrant" | "streamTicket" | "addNetworkHosts" | "answerHandoff" | "grantLoopbackPort" | "revokeLoopbackPort" | "loopbackPorts" | "ensureHostService" | "hostRequest" | "stopHostService" | "personalDevices">;
|
|
107
116
|
/** What `ctx.triggers` calls through (`TriggerEventsService`). */
|
|
108
117
|
export type TriggersBackend = Pick<TriggerEventsService, "emit" | "causeOf">;
|
|
109
118
|
/** What `ctx.inbox` calls through (`InboxItemsService`). */
|
|
@@ -184,8 +193,6 @@ export declare function currentOrgRole(db: KernelDeps["db"], plugin: string, org
|
|
|
184
193
|
* token and the platform refresh stream re-check.
|
|
185
194
|
*/
|
|
186
195
|
export declare function currentPlatformAccount(db: KernelDeps["db"], accountId: string): Promise<boolean>;
|
|
187
|
-
/** 插件的 PG schema 名:`plugin_<name>`,name 中的 `-` 换成 `_`。 */
|
|
188
|
-
export declare function pluginSchemaName(name: string): string;
|
|
189
196
|
/** What {@link resolveUiSlots} returns for a manifest. */
|
|
190
197
|
export type UiResolution = ReturnType<typeof resolveUiSlots>;
|
|
191
198
|
/** 内核视角的插件 ctx:插件契约之外还带宿主要用的登记信息与关闭方法。 */
|
|
@@ -216,6 +223,8 @@ export type KernelExtensionContext = ExtensionContext & {
|
|
|
216
223
|
uiQueries: ReadonlyMap<string, UiQueryHandler>;
|
|
217
224
|
/** Setup checks registered through `ctx.setup.check`, by id. */
|
|
218
225
|
setupChecks: ReadonlyMap<string, RegisteredSetupCheck>;
|
|
226
|
+
/** Handlers registered through `ctx.deviceAccess.onServiceEvent`, by host service name. */
|
|
227
|
+
serviceEventHandlers: ReadonlyMap<string, ServiceEventHandler>;
|
|
219
228
|
/**
|
|
220
229
|
* setup 结束后调用:此后 `tools.register`、`ui.view`、`ui.action`、`hooks.on`、`setup.check` 抛错。
|
|
221
230
|
*/
|
|
@@ -272,4 +281,5 @@ export declare function createExtensionContext(deps: KernelDeps, manifest: Exten
|
|
|
272
281
|
/** The package this instance was loaded from (null: not from an install record). */
|
|
273
282
|
identity?: {
|
|
274
283
|
sha256: string | null;
|
|
284
|
+
db?: Kysely<any>;
|
|
275
285
|
}): KernelExtensionContext;
|
package/dist/ctx/create-ctx.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { CtxReadError, DEVICE_PROVIDER_EXTENSION_POINT, DeviceAccessError, EXTENSION_POINTS, ExtensionPermissionError, ExtensionPointUnavailableError, FILE_PREVIEW_EXTENSION_POINT, InboxError, OBJECT_STORE_EXTENSION_POINT, parseExtensionPoint, resolveUiSlots, SETUP_CHECK_ID_RE, SETUP_GUIDE_PLACES, TriggerError, validateFilePreviewProvider, validateToolSpec, } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { Command, ConnectionBuilder, ControlledTransactionBuilder, Kysely, TransactionBuilder, } from "kysely";
|
|
3
3
|
import { conversationTopic } from "../conversations/event-log.js";
|
|
4
|
+
import { pluginSchemaName } from "../db/extension-db.js";
|
|
4
5
|
import { kernelDb } from "../db/kernel-schema.js";
|
|
5
6
|
import { ApiError } from "../errors.js";
|
|
6
|
-
import { enabledExtensionsQuery
|
|
7
|
+
import { enabledExtensionsQuery } from "../extensions/enabled.js";
|
|
7
8
|
import { checkHookRegistration } from "../extensions/hooks.js";
|
|
8
9
|
import { RegistrationLedger } from "../extensions/ledger.js";
|
|
9
10
|
import { audit } from "../identity/audit.js";
|
|
10
|
-
import { withOrgScope } from "../infra/database/org-scope.js";
|
|
11
|
+
import { currentScope, withOrgScope } from "../infra/database/org-scope.js";
|
|
11
12
|
import { can } from "../orgs/roles.js";
|
|
12
13
|
import { PrefixedStorage } from "../storage/storage.service.js";
|
|
13
14
|
import { canUseSlot, orgUiTopic, PLATFORM_UI_TOPIC, PluginUiRegistration, } from "../ui/registry.js";
|
|
@@ -18,6 +19,7 @@ import { createLock } from "./lock.js";
|
|
|
18
19
|
import { createExtensionNet } from "./net.js";
|
|
19
20
|
import { createQueue } from "./queue.js";
|
|
20
21
|
import { createSecrets } from "./secrets.js";
|
|
22
|
+
export { pluginSchemaName };
|
|
21
23
|
/**
|
|
22
24
|
* A plain-data copy of an emitted event, taken once at the ctx boundary (check-then-use): every
|
|
23
25
|
* own enumerable field is read once (a getter cannot change a value after it was validated),
|
|
@@ -94,20 +96,27 @@ export async function currentPlatformAccount(db, accountId) {
|
|
|
94
96
|
.executeTakeFirst();
|
|
95
97
|
return row !== undefined;
|
|
96
98
|
}
|
|
97
|
-
/**
|
|
99
|
+
/**
|
|
100
|
+
* An invalidation target must be in a live org where the extension is enabled. A supplied
|
|
101
|
+
* conversation must be live and belong to that same org.
|
|
102
|
+
*/
|
|
98
103
|
async function invalidateTargetOk(db, plugin, orgId, conversationId) {
|
|
99
104
|
const k = kernelDb(db);
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
.
|
|
106
|
-
|
|
107
|
-
.where(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
105
|
+
let target = k
|
|
106
|
+
.selectFrom("orgs")
|
|
107
|
+
.innerJoin(enabledExtensionsQuery(k, orgId).as("en"), (join) => join.on("en.plugin", "=", plugin))
|
|
108
|
+
.select("orgs.id")
|
|
109
|
+
.where("orgs.id", "=", orgId)
|
|
110
|
+
.where("orgs.deleted_at", "is", null);
|
|
111
|
+
if (conversationId !== undefined) {
|
|
112
|
+
target = target.where((eb) => eb.exists(eb
|
|
113
|
+
.selectFrom("conversations")
|
|
114
|
+
.select("conversations.id")
|
|
115
|
+
.where("conversations.id", "=", conversationId)
|
|
116
|
+
.where("conversations.org_id", "=", orgId)
|
|
117
|
+
.where("conversations.deleted_at", "is", null)));
|
|
118
|
+
}
|
|
119
|
+
return (await target.executeTakeFirst()) !== undefined;
|
|
111
120
|
}
|
|
112
121
|
/** 越权审计去重键的 TTL:同一插件同一项在此期间只记一次。 */
|
|
113
122
|
const DENIAL_DEDUPE_TTL_SECONDS = 30 * 24 * 3600;
|
|
@@ -138,10 +147,6 @@ async function recordDenial(deps, plugin, item) {
|
|
|
138
147
|
deps.log.warn("plugin permission denial audit failed", { plugin, item, err: e });
|
|
139
148
|
}
|
|
140
149
|
}
|
|
141
|
-
/** 插件的 PG schema 名:`plugin_<name>`,name 中的 `-` 换成 `_`。 */
|
|
142
|
-
export function pluginSchemaName(name) {
|
|
143
|
-
return `plugin_${name.replaceAll("-", "_")}`;
|
|
144
|
-
}
|
|
145
150
|
/**
|
|
146
151
|
* 包装插件拿到的 Kysely:`destroy`(及 `Symbol.asyncDispose`)换成抛错的函数(连接池归内核所有,插件销毁会拖垮整个进程的 DB 访问),
|
|
147
152
|
* 其余属性透传。方法绑定到原对象(Kysely 用私有字段,以 Proxy 作 this 调用会失败)。
|
|
@@ -264,6 +269,7 @@ identity = { sha256: null }) {
|
|
|
264
269
|
// 界面刷新发在内核命名空间(会话主题 conv.<id> / 组织主题 org-ui.<orgId>),不在插件自己的命名空间
|
|
265
270
|
const kernelBus = createBus(deps.redis, deps.busSubscriber, "kernel", deps.log);
|
|
266
271
|
const ledger = new RegistrationLedger(name);
|
|
272
|
+
const serviceEventHandlers = new Map();
|
|
267
273
|
const lifecycle = new AbortController();
|
|
268
274
|
/** 撤销时队列 worker 排空的截止时刻(epoch 毫秒);undefined = 一直等(停机路径)。 */
|
|
269
275
|
let drainDeadline;
|
|
@@ -313,15 +319,22 @@ identity = { sha256: null }) {
|
|
|
313
319
|
// by the declared purpose's kind; an undeclared purpose has none, so its refusal
|
|
314
320
|
// (model.purpose_unknown) names no kind
|
|
315
321
|
describe: async (req) => {
|
|
316
|
-
|
|
322
|
+
const models = deps.models;
|
|
323
|
+
if (!models)
|
|
317
324
|
throw new Error(`plugin ${name}: ctx.models is not available`);
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
|
|
325
|
+
const orgId = req?.orgId;
|
|
326
|
+
const purpose = req?.purpose;
|
|
327
|
+
const kind = declaredModels.find((d) => d.purpose === purpose)?.kind;
|
|
328
|
+
if (kind === undefined && typeof purpose === "string") {
|
|
329
|
+
throw new ApiError("model.purpose_unknown", `Extension ${name} declared no model purpose "${purpose}" in permissions.models`);
|
|
321
330
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
331
|
+
if (typeof orgId !== "string" || orgId === "" || typeof purpose !== "string") {
|
|
332
|
+
throw new ApiError("validation_failed", "describe needs orgId and purpose strings");
|
|
333
|
+
}
|
|
334
|
+
const target = { orgId, purpose };
|
|
335
|
+
return withOrgScope(orgId, () => kind === "image_generation"
|
|
336
|
+
? models.images.describeForExtension(name, declaredModels, target)
|
|
337
|
+
: models.embeddings.describe(name, declaredModels, target));
|
|
325
338
|
},
|
|
326
339
|
}
|
|
327
340
|
: undefined;
|
|
@@ -332,10 +345,11 @@ identity = { sha256: null }) {
|
|
|
332
345
|
const dialInApi = perms.dialIn
|
|
333
346
|
? (() => {
|
|
334
347
|
const access = deps.dialIn;
|
|
335
|
-
const
|
|
348
|
+
const inServedOrg = async (deviceId, run) => {
|
|
336
349
|
if (!access)
|
|
337
350
|
throw new Error(`plugin ${name}: ctx.dialIn is not available`);
|
|
338
|
-
|
|
351
|
+
const orgId = typeof deviceId === "string" ? await access.servedOrg(name, deviceId) : undefined;
|
|
352
|
+
if (orgId === undefined) {
|
|
339
353
|
const item = `dialIn:device ${String(deviceId)}`;
|
|
340
354
|
const p = recordDenial(deps, name, item).finally(() => audits.delete(p));
|
|
341
355
|
audits.add(p);
|
|
@@ -343,36 +357,33 @@ identity = { sha256: null }) {
|
|
|
343
357
|
e.message = `device ${String(deviceId)} is not served by ${name}`;
|
|
344
358
|
throw e;
|
|
345
359
|
}
|
|
346
|
-
return
|
|
360
|
+
return withOrgScope(orgId, () => run(access));
|
|
347
361
|
};
|
|
348
362
|
return {
|
|
349
|
-
request:
|
|
350
|
-
const id = await served(deviceId);
|
|
363
|
+
request: (deviceId, frame, opts) => inServedOrg(deviceId, (dialIn) => {
|
|
351
364
|
const signal = opts?.signal
|
|
352
365
|
? AbortSignal.any([lifecycle.signal, opts.signal])
|
|
353
366
|
: lifecycle.signal;
|
|
354
|
-
//
|
|
355
|
-
return
|
|
367
|
+
// Only the options an extension may pass, excluding the kernel's connection fences.
|
|
368
|
+
return dialIn.request(deviceId, frame, {
|
|
356
369
|
timeoutMs: Number(opts?.timeoutMs),
|
|
357
370
|
signal,
|
|
358
371
|
});
|
|
359
|
-
},
|
|
360
|
-
online:
|
|
361
|
-
capacity:
|
|
372
|
+
}),
|
|
373
|
+
online: (deviceId) => inServedOrg(deviceId, (dialIn) => dialIn.online(deviceId)),
|
|
374
|
+
capacity: (deviceId) => inServedOrg(deviceId, (dialIn) => dialIn.capacity(deviceId)),
|
|
362
375
|
stop: async (deviceId, reason) => {
|
|
363
376
|
if (reason !== "drain" && reason !== "stop")
|
|
364
377
|
throw new TypeError(`plugin ${name}: ctx.dialIn.stop reason must be drain or stop`);
|
|
365
|
-
await
|
|
378
|
+
await inServedOrg(deviceId, (dialIn) => dialIn.stop(deviceId, reason));
|
|
366
379
|
},
|
|
367
|
-
//
|
|
368
|
-
//
|
|
369
|
-
openStream:
|
|
370
|
-
const id = await served(deviceId);
|
|
371
|
-
// the SDK requires the signal: an open nobody can abort is refused up front
|
|
380
|
+
// Only the gateway replica holding the machine's socket opens the stream.
|
|
381
|
+
// The extension's end closes its streams.
|
|
382
|
+
openStream: (deviceId, body, opts) => inServedOrg(deviceId, async (dialIn) => {
|
|
372
383
|
if (!(opts?.signal instanceof AbortSignal))
|
|
373
384
|
throw new TypeError(`plugin ${name}: ctx.dialIn.openStream needs opts.signal`);
|
|
374
385
|
const signal = AbortSignal.any([lifecycle.signal, opts.signal]);
|
|
375
|
-
const stream = await
|
|
386
|
+
const stream = await dialIn.openStream(deviceId, body, signal);
|
|
376
387
|
const onEnd = () => stream.close("extension stopped");
|
|
377
388
|
if (lifecycle.signal.aborted)
|
|
378
389
|
onEnd();
|
|
@@ -381,7 +392,7 @@ identity = { sha256: null }) {
|
|
|
381
392
|
void stream.closed.then(() => lifecycle.signal.removeEventListener("abort", onEnd));
|
|
382
393
|
}
|
|
383
394
|
return stream;
|
|
384
|
-
},
|
|
395
|
+
}),
|
|
385
396
|
};
|
|
386
397
|
})()
|
|
387
398
|
: undefined;
|
|
@@ -390,6 +401,30 @@ identity = { sha256: null }) {
|
|
|
390
401
|
// and, when its revision changed, moves the device authority epoch (device-provider spec §6.7)
|
|
391
402
|
const devicesApi = manifest.provides.includes(DEVICE_PROVIDER_EXTENSION_POINT)
|
|
392
403
|
? {
|
|
404
|
+
// stored with its owed delivery (ServiceEvents); resolves once committed, so the provider
|
|
405
|
+
// acks the machine only then. An event of a service the kernel did not place there as a
|
|
406
|
+
// host service resolves too (dropped, logged): the machine stops sending it
|
|
407
|
+
serviceEvent: async (args) => {
|
|
408
|
+
const events = deps.serviceEvents?.();
|
|
409
|
+
if (!events)
|
|
410
|
+
throw new Error(`plugin ${name}: ctx.devices.serviceEvent is not available`);
|
|
411
|
+
// one snapshot, read once: what is checked is what is stored
|
|
412
|
+
const e = {
|
|
413
|
+
deviceId: args?.deviceId,
|
|
414
|
+
service: args?.service,
|
|
415
|
+
seq: args?.seq,
|
|
416
|
+
body: args?.body,
|
|
417
|
+
};
|
|
418
|
+
const outcome = await events.record(name, e);
|
|
419
|
+
if (outcome === "not-served") {
|
|
420
|
+
const item = `devices:device ${String(e.deviceId)}`;
|
|
421
|
+
const p = recordDenial(deps, name, item).finally(() => audits.delete(p));
|
|
422
|
+
audits.add(p);
|
|
423
|
+
const err = new ExtensionPermissionError(name, `provides ${DEVICE_PROVIDER_EXTENSION_POINT}`);
|
|
424
|
+
err.message = `device ${String(e.deviceId)} is not served by ${name}`;
|
|
425
|
+
throw err;
|
|
426
|
+
}
|
|
427
|
+
},
|
|
393
428
|
reportChanged: async (deviceId) => {
|
|
394
429
|
const reports = deps.devices;
|
|
395
430
|
if (!reports)
|
|
@@ -421,6 +456,8 @@ identity = { sha256: null }) {
|
|
|
421
456
|
// read from the approved manifest: an upgrade adding it waits for approval again
|
|
422
457
|
loopbackPorts: perms.deviceAccess?.loopbackPorts === true,
|
|
423
458
|
siteAccess: perms.deviceAccess?.siteAccess === true,
|
|
459
|
+
// read from the approved manifest: only these may run outside the device sandbox
|
|
460
|
+
hostServices: [...(perms.deviceAccess?.hostServices ?? [])],
|
|
424
461
|
};
|
|
425
462
|
const backend = () => {
|
|
426
463
|
const b = deps.deviceAccess?.();
|
|
@@ -441,6 +478,32 @@ identity = { sha256: null }) {
|
|
|
441
478
|
requestSiteAccess: (call, ask) => backend().requestSiteAccess(caller, call, ask),
|
|
442
479
|
siteGrants: async (scope) => backend().siteGrants(caller, scope),
|
|
443
480
|
revokeSiteGrant: async (scope) => backend().revokeSiteGrant(caller, scope),
|
|
481
|
+
// host services: the approved manifest's hostServices, on the person's own machine
|
|
482
|
+
ensureHostService: async (at, spec) => backend().ensureHostService(caller, at, spec),
|
|
483
|
+
hostRequest: async (at, req) => backend().hostRequest(caller, at, req),
|
|
484
|
+
stopHostService: async (at, service) => backend().stopHostService(caller, at, service),
|
|
485
|
+
personalDevices: async (args) => backend().personalDevices(caller, args),
|
|
486
|
+
// during setup only, for a host service of the approved manifest: the deliveries
|
|
487
|
+
// (ServiceEvents, worker role) call it on whichever replica takes the job
|
|
488
|
+
onServiceEvent: (service, handler) => {
|
|
489
|
+
if (toolsSealed)
|
|
490
|
+
throw new Error(`plugin ${name}: deviceAccess.onServiceEvent is only allowed during setup; setup has completed`);
|
|
491
|
+
if (typeof service !== "string" || !caller.hostServices.includes(service))
|
|
492
|
+
throw new DeviceAccessError("host_not_declared", `The host service ${JSON.stringify(service)} is not declared in permissions.deviceAccess.hostServices.`);
|
|
493
|
+
if (typeof handler !== "function")
|
|
494
|
+
throw new Error(`plugin ${name}: onServiceEvent("${service}") needs a handler function`);
|
|
495
|
+
if (serviceEventHandlers.has(service))
|
|
496
|
+
throw new Error(`plugin ${name}: duplicate onServiceEvent handler for "${service}"`);
|
|
497
|
+
serviceEventHandlers.set(service, handler);
|
|
498
|
+
ledger.add({
|
|
499
|
+
kind: "service.event",
|
|
500
|
+
key: service,
|
|
501
|
+
dispose: async () => {
|
|
502
|
+
if (serviceEventHandlers.get(service) === handler)
|
|
503
|
+
serviceEventHandlers.delete(service);
|
|
504
|
+
},
|
|
505
|
+
});
|
|
506
|
+
},
|
|
444
507
|
};
|
|
445
508
|
})()
|
|
446
509
|
: undefined;
|
|
@@ -667,15 +730,17 @@ identity = { sha256: null }) {
|
|
|
667
730
|
* the org (layering spec A §6: a call on behalf of an org never reaches such a provider).
|
|
668
731
|
*/
|
|
669
732
|
const forOrg = async (orgScoped, orgId, entries) => {
|
|
670
|
-
if (entries.length === 0)
|
|
671
|
-
return
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
733
|
+
if (orgId === "" || entries.length === 0)
|
|
734
|
+
return [];
|
|
735
|
+
return withOrgScope(orgId, async () => {
|
|
736
|
+
let out = entries;
|
|
737
|
+
if (orgScoped) {
|
|
738
|
+
const enabled = await extensionPointAccess.enabledPlugins(orgId);
|
|
739
|
+
out = out.filter((e) => enabled.has(e.plugin));
|
|
740
|
+
}
|
|
741
|
+
const ok = await Promise.all(out.map((e) => extensionPointAccess.configOk(orgId, e.plugin)));
|
|
742
|
+
return out.filter((_, i) => ok[i]);
|
|
743
|
+
});
|
|
679
744
|
};
|
|
680
745
|
const listAll = (ref) => {
|
|
681
746
|
const info = checkExtensionPoint(ref);
|
|
@@ -763,7 +828,7 @@ identity = { sha256: null }) {
|
|
|
763
828
|
},
|
|
764
829
|
add: queue.add,
|
|
765
830
|
},
|
|
766
|
-
db: guardDb(deps.db.withSchema(pluginSchemaName(name)), name),
|
|
831
|
+
db: guardDb((identity.db ?? deps.db).withSchema(pluginSchemaName(name)), name),
|
|
767
832
|
http: {
|
|
768
833
|
route(method, path, handler) {
|
|
769
834
|
if (typeof path !== "string" || !path.startsWith("/")) {
|
|
@@ -939,9 +1004,7 @@ identity = { sha256: null }) {
|
|
|
939
1004
|
},
|
|
940
1005
|
});
|
|
941
1006
|
},
|
|
942
|
-
//
|
|
943
|
-
// (插件拿着过期或别的组织的 id 调用不是错误,但不能借它往别的组织的流里发刷新)。A `platform.page`
|
|
944
|
-
// contribution takes no orgId and refreshes the platform stream (super admins only)
|
|
1007
|
+
// Verify the target before publishing a refresh hint. Platform pages use their own stream.
|
|
945
1008
|
async invalidate(target) {
|
|
946
1009
|
const t = uiReg.target(target, platformUi);
|
|
947
1010
|
// `queries`: the contribution's component queries are refetched too (full pages spec §4.1)
|
|
@@ -955,7 +1018,10 @@ identity = { sha256: null }) {
|
|
|
955
1018
|
await kernelBus.publish(PLATFORM_UI_TOPIC, msg);
|
|
956
1019
|
return;
|
|
957
1020
|
}
|
|
958
|
-
|
|
1021
|
+
const scope = currentScope();
|
|
1022
|
+
const allowed = (scope?.kind !== "org" || scope.orgId === t.orgId) &&
|
|
1023
|
+
(await withOrgScope(t.orgId, () => invalidateTargetOk(deps.db, name, t.orgId, t.conversationId)));
|
|
1024
|
+
if (!allowed) {
|
|
959
1025
|
deps.log.debug?.("plugin ui invalidate ignored: plugin not enabled or conversation not in org", {
|
|
960
1026
|
plugin: name,
|
|
961
1027
|
orgId: t.orgId,
|
|
@@ -1011,6 +1077,7 @@ identity = { sha256: null }) {
|
|
|
1011
1077
|
uiActions: uiReg.actions,
|
|
1012
1078
|
uiQueries: uiReg.queries,
|
|
1013
1079
|
setupChecks,
|
|
1080
|
+
serviceEventHandlers,
|
|
1014
1081
|
ledger,
|
|
1015
1082
|
async beginDispose(deadline) {
|
|
1016
1083
|
drainDeadline = deadline;
|
|
@@ -1037,8 +1104,13 @@ identity = { sha256: null }) {
|
|
|
1037
1104
|
key: r.key,
|
|
1038
1105
|
err,
|
|
1039
1106
|
}));
|
|
1040
|
-
|
|
1041
|
-
|
|
1107
|
+
try {
|
|
1108
|
+
await queue.close();
|
|
1109
|
+
await Promise.allSettled([...audits]);
|
|
1110
|
+
}
|
|
1111
|
+
finally {
|
|
1112
|
+
await identity.db?.destroy();
|
|
1113
|
+
}
|
|
1042
1114
|
})();
|
|
1043
1115
|
return closing;
|
|
1044
1116
|
},
|
package/dist/ctx/queue.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Queue, Worker } from "bullmq";
|
|
2
2
|
import { Redis } from "ioredis";
|
|
3
|
+
import { currentScope } from "../infra/database/org-scope.js";
|
|
3
4
|
import { runJob } from "../infra/queue/run-job.js";
|
|
4
5
|
import { assertNamespace } from "./namespace.js";
|
|
5
6
|
/** 未注入 logger 时的兜底:输出到 stderr。 */
|
|
@@ -62,7 +63,7 @@ export function createQueue(redisUrl, namespace, opts) {
|
|
|
62
63
|
const st = { n: 0, idle: [] };
|
|
63
64
|
active.set(name, st);
|
|
64
65
|
const worker = new Worker(queueName(name),
|
|
65
|
-
//
|
|
66
|
+
// A job from an older producer has no recorded scope and runs unscoped.
|
|
66
67
|
(job) => runJob(queueName(name), job, async () => {
|
|
67
68
|
st.n += 1;
|
|
68
69
|
try {
|
|
@@ -74,7 +75,7 @@ export function createQueue(redisUrl, namespace, opts) {
|
|
|
74
75
|
for (const w of st.idle.splice(0))
|
|
75
76
|
w();
|
|
76
77
|
}
|
|
77
|
-
}),
|
|
78
|
+
}, { scope: job.opts.capybaraScope ?? null }),
|
|
78
79
|
// 撤销插件实例时到点仍未完成的任务被强制留在队列里(锁过期后按 stalled 交回),新实例再执行一次:
|
|
79
80
|
// 任务是至少一次。stalled 次数放宽到 3,连续几次撤销 / 升级不至于把任务判为失败
|
|
80
81
|
{ connection: newConn(), concurrency: o?.concurrency ?? 1, maxStalledCount: 3 });
|
|
@@ -87,14 +88,16 @@ export function createQueue(redisUrl, namespace, opts) {
|
|
|
87
88
|
assertNoColon("queue name", name);
|
|
88
89
|
if (o?.jobId !== undefined)
|
|
89
90
|
assertNoColon("jobId", o.jobId);
|
|
90
|
-
|
|
91
|
+
const jobOptions = {
|
|
92
|
+
capybaraScope: currentScope() ?? null,
|
|
91
93
|
...(o?.jobId !== undefined && { jobId: o.jobId }),
|
|
92
94
|
...(o?.delayMs !== undefined && { delay: o.delayMs }),
|
|
93
95
|
attempts: 3,
|
|
94
96
|
backoff: { type: "exponential", delay: 1000 },
|
|
95
97
|
removeOnComplete: 1000,
|
|
96
98
|
removeOnFail: 5000,
|
|
97
|
-
}
|
|
99
|
+
};
|
|
100
|
+
await getQueue(name).add(name, data, jobOptions);
|
|
98
101
|
},
|
|
99
102
|
async pauseWorkers() {
|
|
100
103
|
await Promise.all([...workers.values()].map((w) => w.pause(true).catch(() => { })));
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import pg from "pg";
|
|
2
|
+
import type { KernelConfig } from "../config/schema.js";
|
|
3
|
+
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
4
|
+
export type ExtensionDbConnection = {
|
|
5
|
+
login: string;
|
|
6
|
+
url: string;
|
|
7
|
+
separate: boolean;
|
|
8
|
+
};
|
|
9
|
+
/** Kernel-owned credentials, resolved from the canonical extension name. */
|
|
10
|
+
export interface ExtensionDbIdentity {
|
|
11
|
+
resolve(name: string): ExtensionDbConnection;
|
|
12
|
+
readonly sharedLogin?: string | undefined;
|
|
13
|
+
}
|
|
14
|
+
export declare class ConfiguredExtensionDbIdentity implements ExtensionDbIdentity {
|
|
15
|
+
private readonly identity;
|
|
16
|
+
constructor(config: KernelConfigService);
|
|
17
|
+
get sharedLogin(): string | undefined;
|
|
18
|
+
resolve(name: string): ExtensionDbConnection;
|
|
19
|
+
}
|
|
20
|
+
export declare function extensionDbIdentity(db: Pick<KernelConfig["db"], "url" | "extensionsUrl">): ExtensionDbIdentity;
|
|
21
|
+
export declare function pluginSchemaName(name: string): string;
|
|
22
|
+
export declare function assertExtensionSession(client: pg.ClientBase, login: string): Promise<void>;
|
|
23
|
+
/** A missing schema is normal before a plugin's first migration. */
|
|
24
|
+
export declare function assertExtensionSchemaOwner(client: pg.ClientBase, schema: string, login: string): Promise<void>;
|
|
25
|
+
/** One small, scope-aware pool per active extension instance. The host owns its lifetime. */
|
|
26
|
+
export declare function extensionDbPool(identity: ExtensionDbConnection, name: string, config: {
|
|
27
|
+
connectTimeoutMs?: number | undefined;
|
|
28
|
+
rls: KernelConfig["db"]["rls"];
|
|
29
|
+
extensionPoolMax: number;
|
|
30
|
+
}, onError?: (error: Error) => void): import("kysely").Kysely<any>;
|