@capybara-hq/kernel 0.1.0-rc.84 → 0.1.0-rc.85
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 +5 -0
- package/dist/admin/health.service.d.ts +2 -2
- package/dist/admin/health.service.js +10 -2
- package/dist/catalog/admin-catalog.controller.d.ts +2 -1
- package/dist/catalog/admin-catalog.controller.js +2 -1
- package/dist/catalog/catalog-content.d.ts +5 -15
- package/dist/catalog/catalog-content.js +5 -56
- package/dist/catalog/catalog-scope.service.d.ts +3 -3
- package/dist/catalog/catalog-scope.service.js +4 -3
- package/dist/catalog/catalog.module.d.ts +3 -1
- package/dist/catalog/catalog.module.js +14 -1
- package/dist/catalog/component-scope.service.d.ts +6 -1
- package/dist/catalog/component-scope.service.js +16 -2
- package/dist/catalog/job-ids.d.ts +29 -0
- package/dist/catalog/job-ids.js +29 -0
- package/dist/catalog/jobs.d.ts +12 -3
- package/dist/catalog/jobs.js +28 -7
- package/dist/catalog/org-catalog.controller.d.ts +2 -30
- package/dist/catalog/org-catalog.controller.js +3 -29
- package/dist/catalog/org-catalog.schemas.d.ts +9 -46
- package/dist/catalog/org-catalog.schemas.js +9 -23
- package/dist/catalog/org-catalog.service.js +14 -23
- package/dist/catalog/plugin-import.d.ts +21 -0
- package/dist/catalog/plugin-import.js +33 -3
- package/dist/catalog/plugin-install.d.ts +69 -76
- package/dist/catalog/plugin-install.js +156 -234
- package/dist/catalog/plugin-upgrade.d.ts +71 -11
- package/dist/catalog/plugin-upgrade.js +222 -43
- package/dist/catalog/scope-sync.d.ts +22 -20
- package/dist/catalog/scope-sync.js +57 -42
- package/dist/catalog/template-connector-ensure.d.ts +100 -0
- package/dist/catalog/template-connector-ensure.js +285 -0
- package/dist/catalog/template-connector-jobs.d.ts +28 -0
- package/dist/catalog/template-connector-jobs.js +54 -0
- package/dist/catalog/template-connector-reconcile.d.ts +44 -0
- package/dist/catalog/template-connector-reconcile.js +114 -0
- package/dist/catalog/template-connectors.processor.d.ts +32 -0
- package/dist/catalog/template-connectors.processor.js +101 -0
- package/dist/db/kernel-schema.d.ts +2 -1
- package/dist/extensions/org-config.d.ts +6 -1
- package/dist/extensions/org-config.js +15 -2
- package/dist/git/gateway.js +3 -1
- package/dist/infra/outbox/registry.d.ts +28 -0
- package/dist/infra/outbox/registry.js +33 -0
- package/dist/infra/queue/queue-names.d.ts +1 -1
- package/dist/infra/queue/queue-names.js +2 -0
- package/dist/lifecycle/kernel-lifecycle.d.ts +8 -1
- package/dist/lifecycle/kernel-lifecycle.js +37 -11
- package/dist/orgs/org-owner.d.ts +7 -0
- package/dist/orgs/org-owner.js +16 -0
- package/dist/platform/operation.d.ts +3 -4
- package/dist/platform/ops/connectors.ops.js +8 -1
- package/dist/platform/ops/org-plugins.ops.d.ts +0 -9
- package/dist/platform/ops/org-plugins.ops.js +18 -235
- package/dist/platform/ops/plugins.ops.d.ts +0 -1
- package/dist/platform/ops/plugins.ops.js +3 -31
- package/dist/roles/worker-role.d.ts +9 -4
- package/dist/roles/worker-role.js +18 -5
- package/dist/roles/worker.module.d.ts +1 -1
- package/dist/roles/worker.module.js +8 -1
- package/dist/setup/setup-guides.service.d.ts +9 -1
- package/dist/setup/setup-guides.service.js +38 -8
- package/dist/tools/admin-connectors.d.ts +3 -2
- package/dist/tools/admin-connectors.js +5 -4
- package/dist/tools/connector-setup.d.ts +28 -0
- package/dist/tools/connector-setup.js +33 -0
- package/dist/tools/connector-tools-jobs.d.ts +35 -0
- package/dist/tools/connector-tools-jobs.js +40 -0
- package/dist/tools/connector-tools.processor.d.ts +32 -0
- package/dist/tools/connector-tools.processor.js +97 -0
- package/dist/tools/connectors.controller.d.ts +1 -0
- package/dist/tools/connectors.schemas.d.ts +1 -0
- package/dist/tools/connectors.schemas.js +5 -0
- package/dist/tools/connectors.service.d.ts +138 -14
- package/dist/tools/connectors.service.js +410 -50
- package/dist/tools/credentials.d.ts +35 -0
- package/dist/tools/credentials.js +89 -1
- package/dist/tools/drift.d.ts +5 -0
- package/dist/tools/drift.js +21 -2
- package/dist/tools/editable-endpoint.d.ts +23 -0
- package/dist/tools/editable-endpoint.js +92 -0
- package/dist/tools/oauth/flow.d.ts +1 -1
- package/dist/tools/oauth/flow.js +3 -2
- package/dist/tools/pipeline.js +14 -5
- package/dist/tools/registry.d.ts +14 -2
- package/dist/tools/registry.js +27 -6
- package/dist/tools/tools.module.js +4 -0
- package/package.json +2 -2
- package/src/migrations/0183_connectors_created_by_nullable.sql +5 -0
|
@@ -617,7 +617,8 @@ export interface ConnectorsTable {
|
|
|
617
617
|
/** `{type, ownership: "org" | "personal", ...非密钥字段}`;凭据在 secrets。 */
|
|
618
618
|
auth: Json<unknown>;
|
|
619
619
|
status: Generated<"active" | "disabled">;
|
|
620
|
-
|
|
620
|
+
/** 0183: null for a connector the kernel created as no person (a scope sync, ruling R17). */
|
|
621
|
+
created_by: string | null;
|
|
621
622
|
created_at: Ts;
|
|
622
623
|
updated_at: Ts;
|
|
623
624
|
deleted_at: TsNullable;
|
|
@@ -3,6 +3,7 @@ import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
|
3
3
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
4
4
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
5
5
|
import { KernelEvents } from "../infra/events/kernel-events.js";
|
|
6
|
+
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
6
7
|
import { OrgLock } from "../orgs/org-lock.js";
|
|
7
8
|
import { EffectiveConfigs } from "./effective-config.js";
|
|
8
9
|
import { ExtensionHost } from "./host.js";
|
|
@@ -120,6 +121,8 @@ export declare class OrgExtensionConfigs {
|
|
|
120
121
|
private readonly effective;
|
|
121
122
|
/** Why an installed extension is not loaded (`status` / `reason` of the unavailable ones). */
|
|
122
123
|
private readonly availability;
|
|
124
|
+
/** Owes the org's template connector ensure when an extension is switched on (ruling R27). */
|
|
125
|
+
private readonly outbox;
|
|
123
126
|
constructor(kdb: KernelDb, txHost: TransactionHost, host: ExtensionHost,
|
|
124
127
|
/** The org row lock (orgs/org-lock.ts): joins the transaction. */
|
|
125
128
|
orgLock: OrgLock,
|
|
@@ -130,7 +133,9 @@ export declare class OrgExtensionConfigs {
|
|
|
130
133
|
/** The effective deployment config of each org (spec A §6): read for `needsConfig`. */
|
|
131
134
|
effective: EffectiveConfigs,
|
|
132
135
|
/** Why an installed extension is not loaded (`status` / `reason` of the unavailable ones). */
|
|
133
|
-
availability: ExtensionAvailability
|
|
136
|
+
availability: ExtensionAvailability,
|
|
137
|
+
/** Owes the org's template connector ensure when an extension is switched on (ruling R27). */
|
|
138
|
+
outbox: Pick<OutboxService, "add">);
|
|
134
139
|
/** The kernel-schema handle of the current transaction. */
|
|
135
140
|
private get db();
|
|
136
141
|
/** After a write committed: a disabled extension's channel connections drop at once. */
|
|
@@ -10,6 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { EXTENSION_POINTS, parseExtensionPoint, } from "@capybara-hq/plugin-sdk";
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
12
|
import { assertItemInstallable, assertPluginSourcesInstallable, disabledPluginItems, pluginItemDisabled, } from "../catalog/request-rules.js";
|
|
13
|
+
import { oweTemplateConnectors } from "../catalog/template-connector-jobs.js";
|
|
13
14
|
import { ApiError } from "../errors.js";
|
|
14
15
|
import { audit } from "../identity/audit.js";
|
|
15
16
|
import { afterCommit } from "../infra/database/after-commit.js";
|
|
@@ -17,6 +18,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
17
18
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
18
19
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
19
20
|
import { KernelEvents } from "../infra/events/kernel-events.js";
|
|
21
|
+
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
20
22
|
import { OrgLock } from "../orgs/org-lock.js";
|
|
21
23
|
import { EffectiveConfigs } from "./effective-config.js";
|
|
22
24
|
import { alwaysOnExtensions, enabledExtensionsQuery, requiredExtensions } from "./enabled.js";
|
|
@@ -61,6 +63,7 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
|
|
|
61
63
|
events;
|
|
62
64
|
effective;
|
|
63
65
|
availability;
|
|
66
|
+
outbox;
|
|
64
67
|
constructor(kdb, txHost, host,
|
|
65
68
|
/** The org row lock (orgs/org-lock.ts): joins the transaction. */
|
|
66
69
|
orgLock,
|
|
@@ -71,7 +74,9 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
|
|
|
71
74
|
/** The effective deployment config of each org (spec A §6): read for `needsConfig`. */
|
|
72
75
|
effective,
|
|
73
76
|
/** Why an installed extension is not loaded (`status` / `reason` of the unavailable ones). */
|
|
74
|
-
availability
|
|
77
|
+
availability,
|
|
78
|
+
/** Owes the org's template connector ensure when an extension is switched on (ruling R27). */
|
|
79
|
+
outbox) {
|
|
75
80
|
this.kdb = kdb;
|
|
76
81
|
this.txHost = txHost;
|
|
77
82
|
this.host = host;
|
|
@@ -80,6 +85,7 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
|
|
|
80
85
|
this.events = events;
|
|
81
86
|
this.effective = effective;
|
|
82
87
|
this.availability = availability;
|
|
88
|
+
this.outbox = outbox;
|
|
83
89
|
}
|
|
84
90
|
/** The kernel-schema handle of the current transaction. */
|
|
85
91
|
get db() {
|
|
@@ -256,6 +262,12 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
|
|
|
256
262
|
updated_at: new Date(),
|
|
257
263
|
}))
|
|
258
264
|
.execute();
|
|
265
|
+
// Switched on: it may provide the connector kind of a template whose plugin is installed in
|
|
266
|
+
// the org without its connector; a worker creates the connectors it never had, once the
|
|
267
|
+
// extension is loaded there (ruling R27)
|
|
268
|
+
if (input.enabled === true && row?.enabled !== true) {
|
|
269
|
+
await oweTemplateConnectors(this.outbox, t, orgId);
|
|
270
|
+
}
|
|
259
271
|
await audit(t, {
|
|
260
272
|
actorAccountId,
|
|
261
273
|
...(actorTokenId !== undefined && { actorTokenId }),
|
|
@@ -491,7 +503,8 @@ OrgExtensionConfigs = __decorate([
|
|
|
491
503
|
__param(4, Inject(ExtensionInstalls)),
|
|
492
504
|
__param(5, Inject(KernelEvents)),
|
|
493
505
|
__param(6, Inject(EffectiveConfigs)),
|
|
494
|
-
__param(7, Inject(ExtensionAvailability))
|
|
506
|
+
__param(7, Inject(ExtensionAvailability)),
|
|
507
|
+
__param(8, Inject(OutboxService))
|
|
495
508
|
], OrgExtensionConfigs);
|
|
496
509
|
export { OrgExtensionConfigs };
|
|
497
510
|
/**
|
package/dist/git/gateway.js
CHANGED
|
@@ -153,6 +153,8 @@ const TOO_MANY = "too many git transfers are running in this organization; try a
|
|
|
153
153
|
const BYTES_EXCEEDED = "this task reached its git transfer limit (tools.git.maxBytesPerRun).";
|
|
154
154
|
const NOT_AN_ENDPOINT = "not a git smart-HTTP endpoint.";
|
|
155
155
|
const reconnect = (host) => `${host} refused the connection's credential. Reconnect it under Settings → Connectors, then run the command again.`;
|
|
156
|
+
/** An org-owned input is missing (the connector is needs_config): not the member's to reconnect. */
|
|
157
|
+
const orgUnconfigured = (host) => `the connector that serves ${host} needs to be configured by an organization admin under Settings → Connectors before it can be used.`;
|
|
156
158
|
const repoRefused = (repo) => `this task may not use the repository ${repo}.`;
|
|
157
159
|
const upstreamFailed = (host, detail) => `the request to ${host} failed (${detail}).`;
|
|
158
160
|
const BAD_PUSH = (why) => `the push could not be read (${why}).`;
|
|
@@ -621,7 +623,7 @@ let GitGateway = class GitGateway {
|
|
|
621
623
|
catch (e) {
|
|
622
624
|
if (e instanceof CredentialMissing) {
|
|
623
625
|
pushResult("refused:credential");
|
|
624
|
-
text(403, reconnect(target.host));
|
|
626
|
+
text(403, e.ownership === "org" ? orgUnconfigured(target.host) : reconnect(target.host));
|
|
625
627
|
return;
|
|
626
628
|
}
|
|
627
629
|
if (e instanceof NetDeniedError) {
|
|
@@ -363,6 +363,34 @@ export declare const OUTBOX_JOBS: {
|
|
|
363
363
|
readonly removeOnFail: 1000;
|
|
364
364
|
};
|
|
365
365
|
};
|
|
366
|
+
readonly "connector-tools-list": {
|
|
367
|
+
readonly queue: "cap-connector-tools";
|
|
368
|
+
readonly idempotent: "Lists the connector's current tools and stores them with the drift compare-and-write under the connector's row lock; a second listing finds the same snapshot and changes nothing";
|
|
369
|
+
readonly processedIn: "packages/kernel/src/tools/connector-tools.processor.ts";
|
|
370
|
+
readonly opts: {
|
|
371
|
+
readonly attempts: 5;
|
|
372
|
+
readonly backoff: {
|
|
373
|
+
readonly type: "exponential";
|
|
374
|
+
readonly delay: 10000;
|
|
375
|
+
};
|
|
376
|
+
readonly removeOnComplete: true;
|
|
377
|
+
readonly removeOnFail: true;
|
|
378
|
+
};
|
|
379
|
+
};
|
|
380
|
+
readonly "template-connectors-ensure": {
|
|
381
|
+
readonly queue: "cap-template-connectors";
|
|
382
|
+
readonly idempotent: "Creates only the template connectors the org never had, each under the org row lock with that rule re-checked, so a second ensure finds them and creates nothing";
|
|
383
|
+
readonly processedIn: "packages/kernel/src/catalog/template-connectors.processor.ts";
|
|
384
|
+
readonly opts: {
|
|
385
|
+
readonly attempts: 8;
|
|
386
|
+
readonly backoff: {
|
|
387
|
+
readonly type: "exponential";
|
|
388
|
+
readonly delay: 5000;
|
|
389
|
+
};
|
|
390
|
+
readonly removeOnComplete: true;
|
|
391
|
+
readonly removeOnFail: true;
|
|
392
|
+
};
|
|
393
|
+
};
|
|
366
394
|
readonly "push-fanout": {
|
|
367
395
|
readonly queue: "cap-push-deliver";
|
|
368
396
|
readonly idempotent: "Owes delivery jobs under deterministic ids; a repeat owes nothing new";
|
|
@@ -328,6 +328,39 @@ export const OUTBOX_JOBS = {
|
|
|
328
328
|
removeOnFail: 1000,
|
|
329
329
|
},
|
|
330
330
|
},
|
|
331
|
+
// `tools/connector-tools-jobs.ts` CONNECTOR_TOOLS_JOB: owed by a deferred connector create, an
|
|
332
|
+
// org admin's save that turns a connector ready, and a personal connector's first member
|
|
333
|
+
// credential, under `connectorToolsJobId` (plugin pages spec §5.2.1)
|
|
334
|
+
"connector-tools-list": {
|
|
335
|
+
queue: "cap-connector-tools",
|
|
336
|
+
idempotent: "Lists the connector's current tools and stores them with the drift compare-and-write under the connector's row lock; a second listing finds the same snapshot and changes nothing",
|
|
337
|
+
processedIn: "packages/kernel/src/tools/connector-tools.processor.ts",
|
|
338
|
+
// 5 attempts, 10 s doubling (an endpoint briefly down); finished and failed jobs removed (each
|
|
339
|
+
// owing has its own id); a connector still without tools is picked up by the drift scan
|
|
340
|
+
opts: {
|
|
341
|
+
attempts: 5,
|
|
342
|
+
backoff: { type: "exponential", delay: 10_000 },
|
|
343
|
+
removeOnComplete: true,
|
|
344
|
+
removeOnFail: true,
|
|
345
|
+
},
|
|
346
|
+
},
|
|
347
|
+
// `catalog/template-connector-jobs.ts` TEMPLATE_CONNECTORS_JOB: owed by an install's commit
|
|
348
|
+
// (`PluginInstaller.markInstalled`) and an org switching an extension on
|
|
349
|
+
// (`OrgExtensionConfigs.put`), under `templateConnectorsJobId` (ruling R27)
|
|
350
|
+
"template-connectors-ensure": {
|
|
351
|
+
queue: "cap-template-connectors",
|
|
352
|
+
idempotent: "Creates only the template connectors the org never had, each under the org row lock with that rule re-checked, so a second ensure finds them and creates nothing",
|
|
353
|
+
processedIn: "packages/kernel/src/catalog/template-connectors.processor.ts",
|
|
354
|
+
// 8 attempts, 5 s doubling (about 10 minutes: a connector extension enabled by the owing
|
|
355
|
+
// transaction loads on the replica within it); finished and failed jobs removed (each owing
|
|
356
|
+
// has its own id)
|
|
357
|
+
opts: {
|
|
358
|
+
attempts: 8,
|
|
359
|
+
backoff: { type: "exponential", delay: 5_000 },
|
|
360
|
+
removeOnComplete: true,
|
|
361
|
+
removeOnFail: true,
|
|
362
|
+
},
|
|
363
|
+
},
|
|
331
364
|
// `push/jobs.ts` PUSH_FANOUT_JOB: one per trigger event, owed in the event's transaction by
|
|
332
365
|
// `PushOwed` under `pushFanoutJobId` (`push-fanout-<eventId>`, mobile app spec §9.4)
|
|
333
366
|
"push-fanout": {
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* (admin/health.service.ts) lists the same names from the feature constants;
|
|
5
5
|
* test/infra/queue-names.test.ts keeps the two equal.
|
|
6
6
|
*/
|
|
7
|
-
export declare const KERNEL_QUEUES: readonly ["cap-kernel-runs", "cap-kernel-subagent-runs", "cap-kernel-channels", "cap-kernel-maintenance", "cap-kernel-plugin-scope", "cap-kernel-titles", "cap-kernel-suggestions", "cap-kernel-usage-report", "cap-kernel-evals", "cap-kernel-lifecycle", "cap-push-deliver"];
|
|
7
|
+
export declare const KERNEL_QUEUES: readonly ["cap-kernel-runs", "cap-kernel-subagent-runs", "cap-kernel-channels", "cap-kernel-maintenance", "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"];
|
|
8
8
|
export type KernelQueueName = (typeof KERNEL_QUEUES)[number];
|
|
@@ -6,6 +6,7 @@ import type { KernelAppOptions } from "../app.js";
|
|
|
6
6
|
import { MarketplacesService } from "../catalog/marketplaces.service.js";
|
|
7
7
|
import { PluginImport } from "../catalog/plugin-import.js";
|
|
8
8
|
import { PlatformPluginUpdater } from "../catalog/plugin-upgrade.js";
|
|
9
|
+
import { TemplateConnectorReconciler } from "../catalog/template-connector-reconcile.js";
|
|
9
10
|
import { ChannelJobs } from "../channels/jobs.js";
|
|
10
11
|
import { ChannelOutbound } from "../channels/outbound.js";
|
|
11
12
|
import { PromptSuggestionQueue } from "../conversations/prompt-suggestions.js";
|
|
@@ -86,6 +87,7 @@ export declare class KernelLifecycle implements OnApplicationBootstrap, BeforeAp
|
|
|
86
87
|
private readonly marketplaces;
|
|
87
88
|
private readonly pluginImport;
|
|
88
89
|
private readonly pluginUpdater;
|
|
90
|
+
private readonly templateConnectors;
|
|
89
91
|
private readonly bus;
|
|
90
92
|
private readonly usageReport;
|
|
91
93
|
private readonly titles;
|
|
@@ -111,7 +113,7 @@ export declare class KernelLifecycle implements OnApplicationBootstrap, BeforeAp
|
|
|
111
113
|
private bootstrapPackages;
|
|
112
114
|
/** The merged bootstrap manifest, read once per start. */
|
|
113
115
|
private mergedManifest;
|
|
114
|
-
constructor(permissionConfig: PermissionConfigPublication, accounts: AccountsService, configService: KernelConfigService, log: KernelLogger, options: KernelAppOptions, pool: Kysely<any>, redis: Redis, kdb: KernelDb, shutdown: GracefulShutdown, host: ExtensionHost, registry: ExtensionRegistry, installs: ExtensionInstalls, blobs: ExtensionBlobs, extensionLifecycle: ExtensionLifecycle, replicaStatus: ReplicaStatusStore, bootstrap: BootstrapService, bootstrapDefaults: BootstrapDefaultsService, marketplaces: MarketplacesService, pluginImport: PluginImport, pluginUpdater: PlatformPluginUpdater, bus: Pick<ExtensionContext["bus"], "publish" | "subscribe">, usageReport: UsageReporter, titles: TitleQueue, suggestions: PromptSuggestionQueue, channelJobs: ChannelJobs, channelOutbound: ChannelOutbound, presence: ReplicaPresence, worker?: WorkerRole | undefined, gateway?: GatewayRole | undefined);
|
|
116
|
+
constructor(permissionConfig: PermissionConfigPublication, accounts: AccountsService, configService: KernelConfigService, log: KernelLogger, options: KernelAppOptions, pool: Kysely<any>, redis: Redis, kdb: KernelDb, shutdown: GracefulShutdown, host: ExtensionHost, registry: ExtensionRegistry, installs: ExtensionInstalls, blobs: ExtensionBlobs, extensionLifecycle: ExtensionLifecycle, replicaStatus: ReplicaStatusStore, bootstrap: BootstrapService, bootstrapDefaults: BootstrapDefaultsService, marketplaces: MarketplacesService, pluginImport: PluginImport, pluginUpdater: PlatformPluginUpdater, templateConnectors: TemplateConnectorReconciler, bus: Pick<ExtensionContext["bus"], "publish" | "subscribe">, usageReport: UsageReporter, titles: TitleQueue, suggestions: PromptSuggestionQueue, channelJobs: ChannelJobs, channelOutbound: ChannelOutbound, presence: ReplicaPresence, worker?: WorkerRole | undefined, gateway?: GatewayRole | undefined);
|
|
115
117
|
/** The kernel HTTP application (set up by `buildKernelApp` before `init()`). */
|
|
116
118
|
get http(): KernelHttpApp;
|
|
117
119
|
attachHttp(http: KernelHttpApp): void;
|
|
@@ -142,6 +144,11 @@ export declare class KernelLifecycle implements OnApplicationBootstrap, BeforeAp
|
|
|
142
144
|
* them too; the final pass imports them, and one that fails is logged like an optional entry.
|
|
143
145
|
*/
|
|
144
146
|
private runBootstrap;
|
|
147
|
+
/**
|
|
148
|
+
* Runs {@link TemplateConnectorReconciler}; an error is logged, except the stop's abort (the
|
|
149
|
+
* checkpoint after it ends the start).
|
|
150
|
+
*/
|
|
151
|
+
private reconcileTemplateConnectors;
|
|
145
152
|
/** 部署尚无活跃超级管理员时提示去初始化;查询失败只记日志,不影响启动。 */
|
|
146
153
|
private warnIfSetupPending;
|
|
147
154
|
beforeApplicationShutdown(): Promise<void>;
|
|
@@ -13,6 +13,7 @@ import { sql } from "kysely";
|
|
|
13
13
|
import { MarketplacesService } from "../catalog/marketplaces.service.js";
|
|
14
14
|
import { PluginImport } from "../catalog/plugin-import.js";
|
|
15
15
|
import { PlatformPluginUpdater } from "../catalog/plugin-upgrade.js";
|
|
16
|
+
import { TemplateConnectorReconciler } from "../catalog/template-connector-reconcile.js";
|
|
16
17
|
import { ChannelJobs } from "../channels/jobs.js";
|
|
17
18
|
import { ChannelOutbound } from "../channels/outbound.js";
|
|
18
19
|
import { PromptSuggestionQueue } from "../conversations/prompt-suggestions.js";
|
|
@@ -109,6 +110,7 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
109
110
|
marketplaces;
|
|
110
111
|
pluginImport;
|
|
111
112
|
pluginUpdater;
|
|
113
|
+
templateConnectors;
|
|
112
114
|
bus;
|
|
113
115
|
usageReport;
|
|
114
116
|
titles;
|
|
@@ -136,7 +138,7 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
136
138
|
mergedManifest;
|
|
137
139
|
constructor(permissionConfig, accounts, configService, log, options,
|
|
138
140
|
// biome-ignore lint/suspicious/noExplicitAny: the pool carries no schema types
|
|
139
|
-
pool, redis, kdb, shutdown, host, registry, installs, blobs, extensionLifecycle, replicaStatus, bootstrap, bootstrapDefaults, marketplaces, pluginImport, pluginUpdater, bus,
|
|
141
|
+
pool, redis, kdb, shutdown, host, registry, installs, blobs, extensionLifecycle, replicaStatus, bootstrap, bootstrapDefaults, marketplaces, pluginImport, pluginUpdater, templateConnectors, bus,
|
|
140
142
|
// the producers closed on every role (their consumers are the worker role's)
|
|
141
143
|
usageReport, titles, suggestions, channelJobs, channelOutbound,
|
|
142
144
|
// this process's presence beat, on every role (admin overview spec §5.1)
|
|
@@ -164,6 +166,7 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
164
166
|
this.marketplaces = marketplaces;
|
|
165
167
|
this.pluginImport = pluginImport;
|
|
166
168
|
this.pluginUpdater = pluginUpdater;
|
|
169
|
+
this.templateConnectors = templateConnectors;
|
|
167
170
|
this.bus = bus;
|
|
168
171
|
this.usageReport = usageReport;
|
|
169
172
|
this.titles = titles;
|
|
@@ -332,6 +335,12 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
332
335
|
await this.runBootstrap(opts.bootstrap.dir, true);
|
|
333
336
|
this.checkpoint();
|
|
334
337
|
}
|
|
338
|
+
// The one-off reconciliation of template connectors (plugin pages spec §7): once the
|
|
339
|
+
// extensions loaded (it plans connectors against their connector extensions) and the bootstrap
|
|
340
|
+
// step's plugins are in, under `lock:bootstrap` (a replica that does not get it skips the
|
|
341
|
+
// pass). Never fails the start: what it could not create waits for a later ensure
|
|
342
|
+
await this.reconcileTemplateConnectors();
|
|
343
|
+
this.checkpoint();
|
|
335
344
|
// The extra manifest's defaults (the platform default theme), at every start whether or not
|
|
336
345
|
// the step ran in it (compose's `init` usually ran it): its themes exist only once the second
|
|
337
346
|
// pass imported them. A no-op once applied or once a super admin chose; never fails the start
|
|
@@ -442,6 +451,22 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
442
451
|
throw e;
|
|
443
452
|
}
|
|
444
453
|
}
|
|
454
|
+
/**
|
|
455
|
+
* Runs {@link TemplateConnectorReconciler}; an error is logged, except the stop's abort (the
|
|
456
|
+
* checkpoint after it ends the start).
|
|
457
|
+
*/
|
|
458
|
+
async reconcileTemplateConnectors() {
|
|
459
|
+
try {
|
|
460
|
+
await this.templateConnectors.run(this.shutdown.signal);
|
|
461
|
+
}
|
|
462
|
+
catch (e) {
|
|
463
|
+
if (this.shutdown.isShuttingDown())
|
|
464
|
+
return;
|
|
465
|
+
this.log.error("template connector reconciliation failed; retried on the next start", {
|
|
466
|
+
error: errMsg(e),
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
}
|
|
445
470
|
/** 部署尚无活跃超级管理员时提示去初始化;查询失败只记日志,不影响启动。 */
|
|
446
471
|
async warnIfSetupPending() {
|
|
447
472
|
try {
|
|
@@ -577,16 +602,17 @@ KernelLifecycle = __decorate([
|
|
|
577
602
|
__param(17, Inject(MarketplacesService)),
|
|
578
603
|
__param(18, Inject(PluginImport)),
|
|
579
604
|
__param(19, Inject(PlatformPluginUpdater)),
|
|
580
|
-
__param(20, Inject(
|
|
581
|
-
__param(21, Inject(
|
|
582
|
-
__param(22, Inject(
|
|
583
|
-
__param(23, Inject(
|
|
584
|
-
__param(24, Inject(
|
|
585
|
-
__param(25, Inject(
|
|
586
|
-
__param(26, Inject(
|
|
587
|
-
__param(27,
|
|
588
|
-
__param(27, Inject(WorkerRole)),
|
|
605
|
+
__param(20, Inject(TemplateConnectorReconciler)),
|
|
606
|
+
__param(21, Inject(KERNEL_BUS)),
|
|
607
|
+
__param(22, Inject(UsageReporter)),
|
|
608
|
+
__param(23, Inject(TitleQueue)),
|
|
609
|
+
__param(24, Inject(PromptSuggestionQueue)),
|
|
610
|
+
__param(25, Inject(ChannelJobs)),
|
|
611
|
+
__param(26, Inject(ChannelOutbound)),
|
|
612
|
+
__param(27, Inject(ReplicaPresence)),
|
|
589
613
|
__param(28, Optional()),
|
|
590
|
-
__param(28, Inject(
|
|
614
|
+
__param(28, Inject(WorkerRole)),
|
|
615
|
+
__param(29, Optional()),
|
|
616
|
+
__param(29, Inject(GatewayRole))
|
|
591
617
|
], KernelLifecycle);
|
|
592
618
|
export { KernelLifecycle };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
2
|
+
/**
|
|
3
|
+
* The org's first owner (earliest membership): the account a kernel-side call acts as where an
|
|
4
|
+
* account id is required but no person acted, such as a connector the kernel created (its
|
|
5
|
+
* `created_by` is null, ruling R17) when its org credential lists tools. Undefined: no owner.
|
|
6
|
+
*/
|
|
7
|
+
export declare function firstOrgOwner(db: KernelSchemaDb, orgId: string): Promise<string | undefined>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The org's first owner (earliest membership): the account a kernel-side call acts as where an
|
|
3
|
+
* account id is required but no person acted, such as a connector the kernel created (its
|
|
4
|
+
* `created_by` is null, ruling R17) when its org credential lists tools. Undefined: no owner.
|
|
5
|
+
*/
|
|
6
|
+
export async function firstOrgOwner(db, orgId) {
|
|
7
|
+
const row = await db
|
|
8
|
+
.selectFrom("memberships")
|
|
9
|
+
.select("account_id")
|
|
10
|
+
.where("org_id", "=", orgId)
|
|
11
|
+
.where("role", "=", "owner")
|
|
12
|
+
.orderBy("created_at")
|
|
13
|
+
.orderBy("account_id")
|
|
14
|
+
.executeTakeFirst();
|
|
15
|
+
return row?.account_id;
|
|
16
|
+
}
|
|
@@ -84,7 +84,7 @@ export interface OperationError {
|
|
|
84
84
|
*
|
|
85
85
|
* Some codes exist only in the tool, never answered by a route: `marketplace.already_added` (the
|
|
86
86
|
* `marketplaces.add` duplicate check is tool policy; the web accepts a duplicate source),
|
|
87
|
-
* `
|
|
87
|
+
* `agent.visibility_web_only`,
|
|
88
88
|
* `catalog.org_owned` (`plugins.set-shown` leaves an org's own plugin to that org),
|
|
89
89
|
* `extension.switch_via_plugin` (`extensions.set-enabled` leaves a catalog plugin's extension to
|
|
90
90
|
* `plugins.set-enabled`),
|
|
@@ -204,9 +204,8 @@ export interface PlatformOperation<I = unknown> {
|
|
|
204
204
|
} | null;
|
|
205
205
|
/**
|
|
206
206
|
* Why the operation takes none of its mirrored route's secret fields (`secret()` meta, left in
|
|
207
|
-
* `omits`) and asks the person for none, e.g. a preview without the credential
|
|
208
|
-
*
|
|
209
|
-
* otherwise requires {@link personFields}.
|
|
207
|
+
* `omits`) and asks the person for none, e.g. a preview without the credential. Rule
|
|
208
|
+
* `platform-op-secret-param` otherwise requires {@link personFields}.
|
|
210
209
|
*/
|
|
211
210
|
withoutSecrets?: string;
|
|
212
211
|
/**
|
|
@@ -115,6 +115,8 @@ const summary = (c) => ({
|
|
|
115
115
|
ownership: "ownership" in c.auth ? (c.auth.ownership ?? null) : null,
|
|
116
116
|
},
|
|
117
117
|
status: c.status,
|
|
118
|
+
// needs_config: an org admin must configure it before it can be used (it is never called)
|
|
119
|
+
setup: c.setup,
|
|
118
120
|
platformTemplateId: c.platformTemplateId,
|
|
119
121
|
description: c.description,
|
|
120
122
|
updatedAt: c.updatedAt,
|
|
@@ -484,7 +486,7 @@ let ConnectorsOperations = class ConnectorsOperations {
|
|
|
484
486
|
}),
|
|
485
487
|
defineOperation({
|
|
486
488
|
id: "connectors.update",
|
|
487
|
-
description: "Edit a connector (org admins): rename it, set or clear its own description (description; null clears it), switch it off or on (status), or use an org-credential connector that declares git hosts for git in sandboxes (useForGit; pushes are then the bot's).
|
|
489
|
+
description: "Edit a connector (org admins): rename it, set or clear its own description (description; null clears it), switch it off or on (status), or use an org-credential connector that declares git hosts for git in sandboxes (useForGit; pushes are then the bot's). For a connector made from a connector template, endpoint changes the fields its template lets the org edit (e.g. { url } for a self-hosted server; other fields are refused); its tools are listed again afterwards, and a change to any field but headers (the url, a base URL, ...) moves the destination: OAuth tokens and members' own credentials are cleared (members connect again), and an OAuth client discovered at the old url too (the connector then needs an org admin's configuration). Credentials are not edited here (connectors.set-org-credential); per-tool state and default policies stay on the connector's web page.",
|
|
488
490
|
input: UpdateInput,
|
|
489
491
|
example: { connectorId: EXAMPLE_ID, name: "Docs (staging)" },
|
|
490
492
|
authz: { orgAction: "connectors.manage" },
|
|
@@ -521,6 +523,11 @@ let ConnectorsOperations = class ConnectorsOperations {
|
|
|
521
523
|
zh.push(i.useForGit ? "用于沙箱中的 git" : "不再用于沙箱中的 git");
|
|
522
524
|
en.push(i.useForGit ? "use it for git in sandboxes" : "stop using it for git");
|
|
523
525
|
}
|
|
526
|
+
if (i.endpoint !== undefined) {
|
|
527
|
+
const fields = Object.keys(i.endpoint).map(named).join(", ");
|
|
528
|
+
zh.push(`修改端点字段 ${fields}`);
|
|
529
|
+
en.push(`change its endpoint fields ${fields}`);
|
|
530
|
+
}
|
|
524
531
|
return {
|
|
525
532
|
zh: `修改连接器「${n}」:${zh.join(",") || "不改动"}`,
|
|
526
533
|
en: `Edit connector "${n}": ${en.join(", ") || "no change"}`,
|
|
@@ -35,15 +35,6 @@ export declare class OrgPluginsOperations implements OnModuleInit {
|
|
|
35
35
|
private readonly themes;
|
|
36
36
|
private readonly config;
|
|
37
37
|
constructor(registry: PlatformOperations, installer: PluginInstaller, orgCatalog: OrgCatalogService, uploads: OrgPluginUploads, owned: OwnedItems, scope: CatalogScopeService, kdb: KernelDb, appearance: AppearanceService, themes: ThemesService, config: KernelConfigService);
|
|
38
|
-
/**
|
|
39
|
-
* What installing a plugin asks the person for (platform web parity spec §7.2): the connector
|
|
40
|
-
* templates whose connector the install creates (on in the org, none kept from an earlier
|
|
41
|
-
* switch-off, as the install wizard asks). The extension's config for the org is its copy of the
|
|
42
|
-
* overridable fields, saved apart (`extensions.save-org-config`).
|
|
43
|
-
*/
|
|
44
|
-
private installTargets;
|
|
45
|
-
/** The missing connectors of an installed plugin that a configure call names. */
|
|
46
|
-
private configureTargets;
|
|
47
38
|
/** The display name of the live plugin of `extension`, or the name when it cannot be read. */
|
|
48
39
|
private pluginNames;
|
|
49
40
|
/** The org's own live plugin `id`, or null (another org's, a platform one, deleted, unknown). */
|