@capybara-hq/kernel 0.1.0-rc.84 → 0.1.0-rc.86
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/marketplaces.service.d.ts +1 -1
- 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/channels/cards.d.ts +7 -3
- package/dist/channels/cards.js +9 -4
- package/dist/channels/phrases.d.ts +10 -0
- package/dist/channels/phrases.js +10 -0
- package/dist/config/docs.js +1 -1
- package/dist/config/schema.d.ts +3 -0
- package/dist/config/schema.js +18 -12
- package/dist/ctx/create-ctx.d.ts +10 -1
- package/dist/ctx/create-ctx.js +42 -2
- package/dist/db/kernel-schema.d.ts +2 -1
- package/dist/device-access/device-access.module.d.ts +7 -0
- package/dist/device-access/device-access.module.js +41 -0
- package/dist/device-access/device-access.service.d.ts +142 -0
- package/dist/device-access/device-access.service.js +464 -0
- package/dist/device-access/token.d.ts +6 -0
- package/dist/device-access/token.js +6 -0
- package/dist/device-access/viewer-routes.d.ts +45 -0
- package/dist/device-access/viewer-routes.js +81 -0
- package/dist/device-access/viewer.d.ts +244 -0
- package/dist/device-access/viewer.js +844 -0
- package/dist/dial-in/access.d.ts +19 -0
- package/dist/dial-in/access.js +23 -0
- package/dist/dial-in/gateway.d.ts +48 -6
- package/dist/dial-in/gateway.js +145 -10
- package/dist/dial-in/keys.d.ts +7 -0
- package/dist/dial-in/keys.js +7 -0
- package/dist/dial-in/routes.d.ts +11 -3
- package/dist/dial-in/routes.js +15 -4
- package/dist/dial-in/streams.d.ts +58 -0
- package/dist/dial-in/streams.js +283 -0
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +2 -0
- package/dist/extensions/host.d.ts +13 -1
- package/dist/extensions/host.js +20 -1
- package/dist/extensions/org-config.d.ts +6 -1
- package/dist/extensions/org-config.js +15 -2
- package/dist/extensions/permission-set.d.ts +15 -1
- package/dist/extensions/permission-set.js +13 -1
- package/dist/extensions/permission-view.d.ts +6 -4
- package/dist/extensions/permission-view.js +6 -1
- package/dist/git/gateway.js +3 -1
- package/dist/http/error.filter.js +2 -0
- package/dist/http/gateway-routes.d.ts +8 -4
- package/dist/http/gateway-routes.js +4 -3
- package/dist/infra/lock/lock.service.d.ts +5 -1
- package/dist/infra/lock/lock.service.js +10 -4
- 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/infra/throttler/named-throttlers.d.ts +3 -0
- package/dist/infra/throttler/named-throttlers.js +16 -0
- package/dist/kernel.module.js +3 -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/gateway-role.d.ts +13 -6
- package/dist/roles/gateway-role.js +27 -9
- package/dist/roles/gateway.module.d.ts +2 -1
- package/dist/roles/gateway.module.js +13 -3
- 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/sandbox/device-services.d.ts +62 -0
- package/dist/sandbox/device-services.js +183 -0
- package/dist/sandbox/leases.d.ts +18 -1
- package/dist/sandbox/leases.js +75 -1
- package/dist/sandbox/network-grants.js +5 -2
- package/dist/sandbox/sandbox.module.d.ts +2 -1
- package/dist/sandbox/sandbox.module.js +5 -2
- package/dist/sandbox/sandbox.service.d.ts +44 -1
- package/dist/sandbox/sandbox.service.js +142 -5
- 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/approvals.service.d.ts +45 -20
- package/dist/tools/approvals.service.js +19 -9
- package/dist/tools/call-scope.d.ts +60 -0
- package/dist/tools/call-scope.js +23 -0
- 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/network-asks.d.ts +13 -0
- package/dist/tools/network-asks.js +26 -2
- package/dist/tools/oauth/flow.d.ts +1 -1
- package/dist/tools/oauth/flow.js +3 -2
- package/dist/tools/pipeline.d.ts +30 -1
- package/dist/tools/pipeline.js +299 -59
- package/dist/tools/questions.service.d.ts +24 -3
- package/dist/tools/questions.service.js +3 -1
- 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 +3 -3
- package/src/migrations/0183_connectors_created_by_nullable.sql +5 -0
|
@@ -7,13 +7,17 @@ export interface GatewayRoutes {
|
|
|
7
7
|
webhooks: Pick<ChannelWebhooks, "handle">;
|
|
8
8
|
/** `channels.webhookMaxBodyBytes`. */
|
|
9
9
|
webhookMaxBodyBytes: number;
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* The device connection route (`GET /device/connect`, environments spec §13.4) and the device
|
|
12
|
+
* stream viewer routes (`GET /device/stream`, the replica hop; browser use spec §6.2).
|
|
13
|
+
*/
|
|
11
14
|
devices: DeviceRoutesOptions;
|
|
12
15
|
}
|
|
13
16
|
/**
|
|
14
17
|
* Registers the gateway role's HTTP routes (`serveGateway = roles.includes("gateway")`): the
|
|
15
|
-
* channel webhook
|
|
16
|
-
* module, so the API's global guard and CSRF check do not apply
|
|
17
|
-
* verification (the channel plugin's signature check, the machine
|
|
18
|
+
* channel webhook, the device connection WebSocket and the device stream viewer WebSockets. These
|
|
19
|
+
* are raw Fastify routes, not a Nest module, so the API's global guard and CSRF check do not apply
|
|
20
|
+
* (P-4); each route does its own verification (the channel plugin's signature check, the machine
|
|
21
|
+
* credential, the viewer ticket, the hop MAC).
|
|
18
22
|
*/
|
|
19
23
|
export declare function registerGatewayRoutes(fastify: FastifyInstance, routes: GatewayRoutes, log: Pick<Logger, "error">): Promise<void>;
|
|
@@ -2,9 +2,10 @@ import { registerChannelWebhookRoute } from "../channels/webhook.controller.js";
|
|
|
2
2
|
import { registerDeviceConnectRoute } from "../dial-in/routes.js";
|
|
3
3
|
/**
|
|
4
4
|
* Registers the gateway role's HTTP routes (`serveGateway = roles.includes("gateway")`): the
|
|
5
|
-
* channel webhook
|
|
6
|
-
* module, so the API's global guard and CSRF check do not apply
|
|
7
|
-
* verification (the channel plugin's signature check, the machine
|
|
5
|
+
* channel webhook, the device connection WebSocket and the device stream viewer WebSockets. These
|
|
6
|
+
* are raw Fastify routes, not a Nest module, so the API's global guard and CSRF check do not apply
|
|
7
|
+
* (P-4); each route does its own verification (the channel plugin's signature check, the machine
|
|
8
|
+
* credential, the viewer ticket, the hop MAC).
|
|
8
9
|
*/
|
|
9
10
|
export async function registerGatewayRoutes(fastify, routes, log) {
|
|
10
11
|
await registerChannelWebhookRoute(fastify, {
|
|
@@ -116,11 +116,15 @@ export declare class LockService {
|
|
|
116
116
|
* TTL/3; any successful renewal through the handle (the watchdog's or an explicit `renew()`)
|
|
117
117
|
* moves it; when it passes without one, `lost` aborts, even with a renewal still in flight. So a
|
|
118
118
|
* holder gives up one renewal period before the key can expire elsewhere. `release` stops
|
|
119
|
-
* renewing and calls `ops.release` once.
|
|
119
|
+
* renewing and calls `ops.release` once. With `ops.quietYield`, a renewal answered `false` is a
|
|
120
|
+
* routine yield (the lease was taken back on purpose, e.g. a stream hold ending for a lifecycle
|
|
121
|
+
* change): it is logged at debug as `lease yielded`, not as a lost lock; a missed deadline is
|
|
122
|
+
* still a WARN.
|
|
120
123
|
*/
|
|
121
124
|
keepAlive(label: string, ttlMs: number, ops: {
|
|
122
125
|
renew(): Promise<boolean>;
|
|
123
126
|
release(): Promise<void>;
|
|
127
|
+
quietYield?: boolean;
|
|
124
128
|
}, acquiredAt?: number): LeaseHandle;
|
|
125
129
|
/** {@link keepAlive}'s implementation, with {@link Watched.renewWith}. */
|
|
126
130
|
private watchdog;
|
|
@@ -257,7 +257,10 @@ let LockService = class LockService {
|
|
|
257
257
|
* TTL/3; any successful renewal through the handle (the watchdog's or an explicit `renew()`)
|
|
258
258
|
* moves it; when it passes without one, `lost` aborts, even with a renewal still in flight. So a
|
|
259
259
|
* holder gives up one renewal period before the key can expire elsewhere. `release` stops
|
|
260
|
-
* renewing and calls `ops.release` once.
|
|
260
|
+
* renewing and calls `ops.release` once. With `ops.quietYield`, a renewal answered `false` is a
|
|
261
|
+
* routine yield (the lease was taken back on purpose, e.g. a stream hold ending for a lifecycle
|
|
262
|
+
* change): it is logged at debug as `lease yielded`, not as a lost lock; a missed deadline is
|
|
263
|
+
* still a WARN.
|
|
261
264
|
*/
|
|
262
265
|
keepAlive(label, ttlMs, ops, acquiredAt = Date.now()) {
|
|
263
266
|
return this.watchdog(label, ttlMs, ops, acquiredAt);
|
|
@@ -277,11 +280,14 @@ let LockService = class LockService {
|
|
|
277
280
|
clearInterval(timer);
|
|
278
281
|
clearTimeout(deadline);
|
|
279
282
|
};
|
|
280
|
-
const lose = (reason) => {
|
|
283
|
+
const lose = (reason, refused = false) => {
|
|
281
284
|
// released or abandoned: the holder gave the lease up, so a late answer loses nothing
|
|
282
285
|
if (released || stopped || lost.signal.aborted)
|
|
283
286
|
return;
|
|
284
|
-
|
|
287
|
+
if (refused && ops.quietYield)
|
|
288
|
+
this.log.debug("lease yielded", { lockKey });
|
|
289
|
+
else
|
|
290
|
+
this.log.warn(reason, { lockKey });
|
|
285
291
|
lost.abort(new Error(`lock lost: ${lockKey}`));
|
|
286
292
|
stop();
|
|
287
293
|
};
|
|
@@ -301,7 +307,7 @@ let LockService = class LockService {
|
|
|
301
307
|
if (released || lost.signal.aborted)
|
|
302
308
|
return false;
|
|
303
309
|
if (!ok) {
|
|
304
|
-
lose("lock lost: the key is gone or taken");
|
|
310
|
+
lose("lock lost: the key is gone or taken", true);
|
|
305
311
|
return false;
|
|
306
312
|
}
|
|
307
313
|
if (sentAt > lastOkSentAt) {
|
|
@@ -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];
|
|
@@ -40,6 +40,9 @@ export interface NamedThrottler {
|
|
|
40
40
|
* `app-auth-token-ip` the same way (the one-time code is 32 random bytes).
|
|
41
41
|
* `POST …/guides/:guideId/checks/:checkId/run` opts in to `setup-check` (setup guides v2 §10.3: each run may call a third party).
|
|
42
42
|
*
|
|
43
|
+
* `device-stream-ip` is not a Nest route limit either: the gateway's raw viewer route
|
|
44
|
+
* `GET /device/stream` reserves it before the upgrade (429 `rate_limited`).
|
|
45
|
+
*
|
|
43
46
|
* `plugin-public-write` is not a Nest route limit: the plugin dispatch counts it for unsafe
|
|
44
47
|
* methods on `public` extension routes (`PluginRouteAccess`).
|
|
45
48
|
*/
|
|
@@ -41,6 +41,9 @@ const LOGIN_MSG = "Too many failed login attempts; try again later";
|
|
|
41
41
|
* `app-auth-token-ip` the same way (the one-time code is 32 random bytes).
|
|
42
42
|
* `POST …/guides/:guideId/checks/:checkId/run` opts in to `setup-check` (setup guides v2 §10.3: each run may call a third party).
|
|
43
43
|
*
|
|
44
|
+
* `device-stream-ip` is not a Nest route limit either: the gateway's raw viewer route
|
|
45
|
+
* `GET /device/stream` reserves it before the upgrade (429 `rate_limited`).
|
|
46
|
+
*
|
|
44
47
|
* `plugin-public-write` is not a Nest route limit: the plugin dispatch counts it for unsafe
|
|
45
48
|
* methods on `public` extension routes (`PluginRouteAccess`).
|
|
46
49
|
*/
|
|
@@ -152,6 +155,19 @@ export const NAMED_THROTTLERS = [
|
|
|
152
155
|
message: "Too many device sign-in polls; try again later",
|
|
153
156
|
getTracker: ip,
|
|
154
157
|
},
|
|
158
|
+
// device stream viewer upgrades per client address (`GET /device/stream`, a raw gateway route
|
|
159
|
+
// reserving through CredentialThrottler before the upgrade): every attempt costs a ticket
|
|
160
|
+
// GETDEL, so an unauthenticated flood is bounded; a panel reconnects a few times a minute
|
|
161
|
+
{
|
|
162
|
+
name: "device-stream-ip",
|
|
163
|
+
group: "device-stream",
|
|
164
|
+
onSuccess: "refund",
|
|
165
|
+
limit: 120,
|
|
166
|
+
ttl: 60_000,
|
|
167
|
+
code: "rate_limited",
|
|
168
|
+
message: "Too many device stream connections; try again later",
|
|
169
|
+
getTracker: ip,
|
|
170
|
+
},
|
|
155
171
|
// native-app sign-in code exchanges per client address (@Throttled like device-token-ip): 60.
|
|
156
172
|
// The code is 32 random bytes and dies at its first try, so this only bounds the load
|
|
157
173
|
{
|
package/dist/kernel.module.js
CHANGED
|
@@ -12,6 +12,7 @@ import { ChannelsModule } from "./channels/channels.module.js";
|
|
|
12
12
|
import { ClientModule } from "./client/client.module.js";
|
|
13
13
|
import { PromptSuggestionsModule } from "./conversations/prompt-suggestions.js";
|
|
14
14
|
import { TitlesModule } from "./conversations/titles.js";
|
|
15
|
+
import { ExtensionDeviceAccessModule } from "./device-access/device-access.module.js";
|
|
15
16
|
import { BootstrapDefaultsService } from "./extensions/bootstrap-defaults.js";
|
|
16
17
|
import { ExtensionsModule } from "./extensions/extensions.module.js";
|
|
17
18
|
import { ApiModule } from "./http/api.module.js";
|
|
@@ -128,6 +129,8 @@ let KernelModule = KernelModule_1 = class KernelModule {
|
|
|
128
129
|
PluginRouteAccessModule,
|
|
129
130
|
// client extensions: the client builds stored with extension packages
|
|
130
131
|
ClientModule,
|
|
132
|
+
// ctx.deviceAccess: extensions' device services (the host finds it at the time of use)
|
|
133
|
+
ExtensionDeviceAccessModule,
|
|
131
134
|
// the Platform tool's operation registry and actor facts
|
|
132
135
|
PlatformModule,
|
|
133
136
|
// its operations (skills, agents, ...), registered at start on every role
|
|
@@ -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). */
|