@capybara-hq/kernel 0.1.0-rc.83 → 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.
Files changed (94) hide show
  1. package/dist/admin/admin.module.js +5 -0
  2. package/dist/admin/health.service.d.ts +2 -2
  3. package/dist/admin/health.service.js +10 -2
  4. package/dist/catalog/admin-catalog.controller.d.ts +2 -1
  5. package/dist/catalog/admin-catalog.controller.js +2 -1
  6. package/dist/catalog/catalog-content.d.ts +5 -15
  7. package/dist/catalog/catalog-content.js +5 -56
  8. package/dist/catalog/catalog-scope.service.d.ts +3 -3
  9. package/dist/catalog/catalog-scope.service.js +4 -3
  10. package/dist/catalog/catalog.module.d.ts +3 -1
  11. package/dist/catalog/catalog.module.js +14 -1
  12. package/dist/catalog/component-scope.service.d.ts +6 -1
  13. package/dist/catalog/component-scope.service.js +16 -2
  14. package/dist/catalog/git-source.d.ts +8 -0
  15. package/dist/catalog/git-source.js +34 -0
  16. package/dist/catalog/job-ids.d.ts +29 -0
  17. package/dist/catalog/job-ids.js +29 -0
  18. package/dist/catalog/jobs.d.ts +12 -3
  19. package/dist/catalog/jobs.js +28 -7
  20. package/dist/catalog/marketplaces.service.d.ts +1 -1
  21. package/dist/catalog/org-catalog.controller.d.ts +2 -30
  22. package/dist/catalog/org-catalog.controller.js +3 -29
  23. package/dist/catalog/org-catalog.schemas.d.ts +9 -46
  24. package/dist/catalog/org-catalog.schemas.js +9 -23
  25. package/dist/catalog/org-catalog.service.js +14 -23
  26. package/dist/catalog/plugin-import.d.ts +21 -0
  27. package/dist/catalog/plugin-import.js +33 -3
  28. package/dist/catalog/plugin-install.d.ts +69 -76
  29. package/dist/catalog/plugin-install.js +156 -234
  30. package/dist/catalog/plugin-upgrade.d.ts +71 -11
  31. package/dist/catalog/plugin-upgrade.js +222 -43
  32. package/dist/catalog/scope-sync.d.ts +22 -20
  33. package/dist/catalog/scope-sync.js +57 -42
  34. package/dist/catalog/template-connector-ensure.d.ts +100 -0
  35. package/dist/catalog/template-connector-ensure.js +285 -0
  36. package/dist/catalog/template-connector-jobs.d.ts +28 -0
  37. package/dist/catalog/template-connector-jobs.js +54 -0
  38. package/dist/catalog/template-connector-reconcile.d.ts +44 -0
  39. package/dist/catalog/template-connector-reconcile.js +114 -0
  40. package/dist/catalog/template-connectors.processor.d.ts +32 -0
  41. package/dist/catalog/template-connectors.processor.js +101 -0
  42. package/dist/db/kernel-schema.d.ts +2 -1
  43. package/dist/extensions/bootstrap.js +5 -1
  44. package/dist/extensions/instance.js +1 -16
  45. package/dist/extensions/org-config.d.ts +6 -1
  46. package/dist/extensions/org-config.js +15 -2
  47. package/dist/git/gateway.js +3 -1
  48. package/dist/infra/outbox/registry.d.ts +28 -0
  49. package/dist/infra/outbox/registry.js +33 -0
  50. package/dist/infra/queue/queue-names.d.ts +1 -1
  51. package/dist/infra/queue/queue-names.js +2 -0
  52. package/dist/lifecycle/kernel-lifecycle.d.ts +8 -1
  53. package/dist/lifecycle/kernel-lifecycle.js +37 -11
  54. package/dist/orgs/org-owner.d.ts +7 -0
  55. package/dist/orgs/org-owner.js +16 -0
  56. package/dist/platform/operation.d.ts +3 -4
  57. package/dist/platform/ops/connectors.ops.js +8 -1
  58. package/dist/platform/ops/org-plugins.ops.d.ts +0 -9
  59. package/dist/platform/ops/org-plugins.ops.js +18 -235
  60. package/dist/platform/ops/plugins.ops.d.ts +0 -1
  61. package/dist/platform/ops/plugins.ops.js +3 -31
  62. package/dist/roles/worker-role.d.ts +9 -4
  63. package/dist/roles/worker-role.js +18 -5
  64. package/dist/roles/worker.module.d.ts +1 -1
  65. package/dist/roles/worker.module.js +8 -1
  66. package/dist/setup/setup-guides.service.d.ts +9 -1
  67. package/dist/setup/setup-guides.service.js +38 -8
  68. package/dist/tools/admin-connectors.d.ts +3 -2
  69. package/dist/tools/admin-connectors.js +5 -4
  70. package/dist/tools/connector-setup.d.ts +28 -0
  71. package/dist/tools/connector-setup.js +33 -0
  72. package/dist/tools/connector-tools-jobs.d.ts +35 -0
  73. package/dist/tools/connector-tools-jobs.js +40 -0
  74. package/dist/tools/connector-tools.processor.d.ts +32 -0
  75. package/dist/tools/connector-tools.processor.js +97 -0
  76. package/dist/tools/connectors.controller.d.ts +1 -0
  77. package/dist/tools/connectors.schemas.d.ts +1 -0
  78. package/dist/tools/connectors.schemas.js +5 -0
  79. package/dist/tools/connectors.service.d.ts +138 -14
  80. package/dist/tools/connectors.service.js +410 -50
  81. package/dist/tools/credentials.d.ts +35 -0
  82. package/dist/tools/credentials.js +89 -1
  83. package/dist/tools/drift.d.ts +5 -0
  84. package/dist/tools/drift.js +21 -2
  85. package/dist/tools/editable-endpoint.d.ts +23 -0
  86. package/dist/tools/editable-endpoint.js +92 -0
  87. package/dist/tools/oauth/flow.d.ts +1 -1
  88. package/dist/tools/oauth/flow.js +3 -2
  89. package/dist/tools/pipeline.js +14 -5
  90. package/dist/tools/registry.d.ts +14 -2
  91. package/dist/tools/registry.js +27 -6
  92. package/dist/tools/tools.module.js +4 -0
  93. package/package.json +3 -3
  94. package/src/migrations/0183_connectors_created_by_nullable.sql +5 -0
@@ -1,11 +1,11 @@
1
- import { type AgentTemplate, type ConnectorTemplateFile, type ConnectorTemplateSpec, type PluginManifest } from "@capybara-hq/plugin-sdk";
1
+ import { type AgentTemplate, type ConnectorTemplateFile, type PluginManifest } from "@capybara-hq/plugin-sdk";
2
2
  import type { KernelSchemaDb, PluginInstallStatus, SourceFormat } from "../db/kernel-schema.js";
3
- import { ApiError } from "../errors.js";
4
3
  import { OrgExtensionConfigs, type OrgExtensionInput, type OrgExtensionPutOptions } from "../extensions/org-config.js";
5
4
  import { ExtensionRegistry } from "../extensions/registry.js";
6
5
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
7
6
  import { KernelDb } from "../infra/database/kernel-db.js";
8
7
  import { TransactionHost } from "../infra/database/transaction-host.js";
8
+ import { OutboxService } from "../infra/outbox/outbox.service.js";
9
9
  import type { KernelLogger } from "../log.js";
10
10
  import { OrgLock } from "../orgs/org-lock.js";
11
11
  import type { OrgAction } from "../orgs/roles.js";
@@ -16,7 +16,11 @@ import type { ConnectorDetail, CreateConnectorInput, ToolIssue } from "../tools/
16
16
  import { ConnectorsService } from "../tools/connectors.service.js";
17
17
  import { type CatalogVersionFiles, type TemplateDeps } from "./catalog-content.js";
18
18
  import { type DefinitionRefs, type TemplateSwitch } from "./component-state.js";
19
- /** What an org fills in for one connector template at install (C30). */
19
+ /**
20
+ * What an org fills in for one more connector from a connector template (C30; `POST …/
21
+ * connector-templates/:templateId/connectors`). Installs and enables take none (plugin pages spec
22
+ * §5.2.2).
23
+ */
20
24
  export interface ConnectorInstallInput {
21
25
  name?: string;
22
26
  slug?: string;
@@ -29,12 +33,12 @@ export interface ConnectorInstallInput {
29
33
  };
30
34
  }
31
35
  /**
32
- * What an org fills in when installing a plugin (the body of `POST …/catalog/:itemId/install`
33
- * without `version`). Dependencies get no input: one whose templates need credentials is installed
34
- * on its own first.
36
+ * What an org chooses when installing a plugin (the body of `POST …/catalog/:itemId/install`
37
+ * without `version`). No connector input (plugin pages spec §5.2.2): every connector template on
38
+ * becomes a connector, one that lacks an org credential or OAuth client waits as `needs_config`.
39
+ * Dependencies get no choice.
35
40
  */
36
41
  export interface PluginInstallInput {
37
- connectors?: Record<string, ConnectorInstallInput>;
38
42
  /**
39
43
  * The connector templates the org chose to switch on with the install (the install wizard's choose step):
40
44
  * exactly these are on afterwards, the others switched off in the org. Absent: the templates on
@@ -101,11 +105,6 @@ export interface UninstallPreview {
101
105
  export declare function uninstallPreviewHash(p: UninstallPreview): string;
102
106
  /** Upserts the org's switch row of an item in the caller's transaction (the org lock is held). */
103
107
  export declare function upsertOrgSwitch(db: KernelSchemaDb, orgId: string, itemId: string, enabled: boolean, actor: string | null): Promise<void>;
104
- /** The kernel (actor null, the scope sync) never installs what needs the org's input. */
105
- export declare class NeedsOrgInput extends ApiError {
106
- readonly plugin: string;
107
- constructor(plugin: string);
108
- }
109
108
  /** A plugin install in an org (`GET /orgs/:orgId/plugin-installs`). */
110
109
  export interface PluginInstallView {
111
110
  id: string;
@@ -232,17 +231,6 @@ export interface UninstallCtx {
232
231
  * {@link DEPENDENCY_DEPTH_LIMIT} -> `catalog.dependency_cycle`. Returns the direct dependencies.
233
232
  */
234
233
  export declare function resolveDependencies(db: KernelSchemaDb, manifest: PluginManifest): Promise<ResolvedDependency[]>;
235
- /**
236
- * The input a template needs that the org did not give: a static credential (the org's for an
237
- * org-owned template; for a personal one the installer's own, stored as their personal credential,
238
- * since creating the connector lists its tools with it), or the OAuth client of a
239
- * client-credentials / manual-client template. Undefined when nothing is missing.
240
- * `personalCredential: false` keeps a personal static template optional (an existing connector
241
- * whose template's auth changed: its members keep giving their own).
242
- */
243
- export declare function missingTemplateInput(template: ConnectorTemplateSpec, given: ConnectorInstallInput | undefined, o?: {
244
- personalCredential?: boolean;
245
- }): "credential" | "client" | undefined;
246
234
  /** `e` with its validation paths under `at` (input errors of a template's connector). */
247
235
  export declare function under(e: unknown, at: string): unknown;
248
236
  /**
@@ -285,6 +273,8 @@ export declare class PluginInstaller {
285
273
  /** Org connectors: installs create, upgrade and remove them. */
286
274
  private readonly connectors;
287
275
  private readonly log;
276
+ /** Owes the template connector ensure of an install's commit (`markInstalled`). */
277
+ private readonly outbox;
288
278
  readonly txHost: TransactionHost;
289
279
  constructor(kdb: KernelDb,
290
280
  /** The org row lock (orgs/org-lock.ts): joins the caller's transaction. */
@@ -292,7 +282,9 @@ export declare class PluginInstaller {
292
282
  /** The loaded extensions and connectors of this replica (the extension registry). */
293
283
  registry: ExtensionRegistry, skills: SkillsService, orgConfigs: OrgExtensionConfigs, config: KernelConfigService,
294
284
  /** Org connectors: installs create, upgrade and remove them. */
295
- connectors: ConnectorsService, log: KernelLogger, txHost: TransactionHost);
285
+ connectors: ConnectorsService, log: KernelLogger,
286
+ /** Owes the template connector ensure of an install's commit (`markInstalled`). */
287
+ outbox: Pick<OutboxService, "add">, txHost: TransactionHost);
296
288
  /** The kernel-schema handle of the current context (the transaction, else the pool). */
297
289
  private get db();
298
290
  /** `catalog.staleInstallMinutes`: an install `installing` for longer can be cleaned up by uninstalling it. */
@@ -328,9 +320,10 @@ export declare class PluginInstaller {
328
320
  templateDeps(): TemplateDeps;
329
321
  /**
330
322
  * Plans the install of one plugin version and, depth first, of its dependencies not yet
331
- * installed in the org. `input` null skips the input checks (preflight); dependencies always get
332
- * an empty input. `at` prefixes validation paths (`dependencies.<name>.` for a dependency);
333
- * `approvedBy` is the root item for a dependency.
323
+ * installed in the org. `input` null plans no connectors (preflight, the scope preview: only the
324
+ * templates' connector extensions are checked); dependencies always get an empty input. `at`
325
+ * prefixes validation paths (`dependencies.<name>.` for a dependency); `approvedBy` is the root
326
+ * item for a dependency.
334
327
  */
335
328
  plan(orgId: string, actor: string | null, itemId: string, version: string, input: PluginInstallInput | null, at: string, approvedBy: string | undefined): Promise<InstallPlan>;
336
329
  /**
@@ -353,18 +346,20 @@ export declare class PluginInstaller {
353
346
  name: string;
354
347
  }[]): Promise<ResolvedDependency[]>;
355
348
  /**
356
- * The connector input of one template from the org's input (C30), checked without a connection:
357
- * the template's connector extension deployed, the input valid, the credential / OAuth client it
358
- * needs given (else 400; a dependency's says to install it on its own first).
349
+ * The connector of one template as an install creates it (plugin pages spec §5.2.2), checked
350
+ * without a connection: the template's connector extension deployed and its preset valid. No
351
+ * input is asked for: a template that needs an org credential or OAuth client becomes a
352
+ * `needs_config` connector ({@link setupNeed}), one that needs none `ready`. The name and slug
353
+ * are the first free defaults, chosen under the org lock (`slugDefault`), so an org connector of
354
+ * the same slug never blocks an install nobody can give input to.
359
355
  */
360
- planConnector(actor: string, plugin: {
356
+ planConnector(actor: string | null, plugin: {
361
357
  itemId: string;
362
358
  version: string;
363
- name: string;
364
359
  }, ct: {
365
360
  id: string;
366
361
  file: ConnectorTemplateFile;
367
- }, input: PluginInstallInput, at: string, approvedBy: string | undefined): CreateConnectorInput;
362
+ }, at: string, approvedBy: string | undefined): CreateConnectorInput;
368
363
  /**
369
364
  * The org's live install of a dependency's item (installing or installed), or undefined. One at a
370
365
  * version outside the dependency's range -> `catalog.dependency_unresolved` (org upgrades arrive in
@@ -426,8 +421,6 @@ export declare class PluginInstaller {
426
421
  * unaffected.
427
422
  */
428
423
  planExtension(orgId: string, manifest: PluginManifest): Promise<string | null>;
429
- /** The input only names the plugin's template ids. */
430
- private checkInput;
431
424
  /**
432
425
  * Undoes the components this install created, in reverse order (the role is not re-checked: it
433
426
  * undoes this install's own changes); returns the ones that failed. The component rows of undone
@@ -526,25 +519,11 @@ export declare class PluginInstaller {
526
519
  /**
527
520
  * Installs the dependencies an installed plugin's version declares and the org lacks (rule 9),
528
521
  * as the kernel (actor null): a platform update can add one. Each is recorded on the install
529
- * as a `plugin` component (created when this installed it, so an uninstall takes it along). One
530
- * that needs the org's input (connector templates) is left out and its name returned. A
531
- * dependency already installed in the org is recorded as it is (created false).
522
+ * as a `plugin` component (created when this installed it, so an uninstall takes it along); its
523
+ * connector templates become connectors as at any install. A dependency already installed in
524
+ * the org is recorded as it is (created false). Returns how many dependencies it installed.
532
525
  */
533
- addMissingDependencies(orgId: string, installId: string): Promise<string[]>;
534
- /**
535
- * The connector templates of an installed plugin that are on in the org (ruling P2-6) and have
536
- * no live connector there: made from the platform template (`platform_template_id`) or recorded
537
- * on the install (`template_id`). The org's plugin is `needs_config` while any is missing (ruling
538
- * P2-10). Empty for a plugin not installed.
539
- */
540
- missingConnectors(orgId: string, itemId: string): Promise<{
541
- installId: string;
542
- version: string;
543
- templates: {
544
- id: string;
545
- file: ConnectorTemplateFile;
546
- }[];
547
- } | undefined>;
526
+ addMissingDependencies(orgId: string, installId: string): Promise<number>;
548
527
  /**
549
528
  * The org's live connectors made from one of the item's connector templates, oldest first
550
529
  * (`templateId` picks one): an uninstall keeps a connector its agents use, and the plugin's next
@@ -555,34 +534,23 @@ export declare class PluginInstaller {
555
534
  private liveTemplateConnector;
556
535
  /**
557
536
  * The org's connector templates it already has a live connector for, by template id: the install
558
- * takes that connector back instead of creating one, so the org item detail tells the wizard not
559
- * to ask for their input (the same join as {@link liveTemplateConnector}).
537
+ * takes that connector back instead of creating one (the same join as
538
+ * {@link liveTemplateConnector}).
560
539
  */
561
540
  connectedTemplates(orgId: string, itemId: string): Promise<Set<string>>;
562
- /**
563
- * Creates the connectors an installed plugin is missing (ruling P2-10, `POST …/catalog/:itemId/
564
- * connectors`): `input.connectors` names some of {@link missingConnectors}' templates with the
565
- * same input as an install (endpoint, credential or OAuth client); each is created as at install
566
- * and recorded on the install. Returns the created connectors by template.
567
- */
568
- configureConnectors(orgId: string, actor: string, itemId: string, input: PluginInstallInput, opts?: {
569
- actorTokenId?: string;
570
- auditDetail?: AuditDetail;
571
- }): Promise<{
572
- templateId: string;
573
- connectorId: string;
574
- }[]>;
575
- /** A configured connector's ledger row (its own transaction). */
576
- private recordConnector;
577
541
  /**
578
542
  * One more connector from a platform connector template on in the org (rulings P4-7, P4-T6-8;
579
543
  * `POST …/connector-templates/:templateId/connectors`): `templateId` is the platform connector
580
- * template's id; `config` is an install's connector input (endpoint, credential or OAuth client,
581
- * slug) and `name` its name. Without a slug the name and slug default to the first free ones,
582
- * chosen by the create under the org lock after its outbound calls
583
- * (`CreateConnectorInput.slugDefault`); only a given slug answers 409 `connector.slug_taken`. Created as at install ({@link planConnector}, then
584
- * `ConnectorsService.create`, which checks the slug before any outbound call and re-checks it,
585
- * `connectors.manage`, the item and the template being on under the org lock), linked to the
544
+ * template's id; `config` is the connector's input (endpoint, credential or OAuth client, slug)
545
+ * and `name` its name. Without a slug the name and slug default to the first free ones, chosen
546
+ * by the create under the org lock after its outbound calls (`CreateConnectorInput.slugDefault`);
547
+ * only a given slug answers 409 `connector.slug_taken`. As on the connectors page's own create,
548
+ * the org credential or OAuth client the template needs is required; a personal static template
549
+ * given no credential is created ready without one, and a `dcr` one without a client
550
+ * (`createDeferredIn`: its members connect their own, the client registers on the first
551
+ * connect). Otherwise created by `ConnectorsService.create`, which lists the tools, checks the
552
+ * slug before any outbound call and re-checks it, `connectors.manage`, the item and the
553
+ * template being on under the org lock. Linked to the
586
554
  * template, and recorded on the plugin's live install in the org when there is one. A template
587
555
  * that is missing, deleted or not offered to the org -> 404 `component.not_found`; offered but
588
556
  * off there (its plugin not installed, or switched off) -> 409 `component.off`; input errors ->
@@ -598,11 +566,36 @@ export declare class PluginInstaller {
598
566
  connector: ConnectorDetail;
599
567
  issues: ToolIssue[];
600
568
  }>;
569
+ /**
570
+ * The connector of a platform connector template an org admin just switched on (plugin pages
571
+ * spec §5.2.2: a template switched on later creates its connector under the install rule), in
572
+ * the switch's transaction: only where the org has the template's plugin installed and no live
573
+ * connector from the template yet (one a switch-off kept is reused, left as it is). Created like
574
+ * an install's ({@link planConnector}, `createDeferredIn`: no outbound call, `needs_config` when
575
+ * it needs an org credential or OAuth client) and recorded on the install. Returns its id, or
576
+ * undefined when none was created. `actor` null: the kernel itself (the startup reconciliation,
577
+ * `TemplateConnectorReconciler`), which checks the template is on and holds the org lock.
578
+ */
579
+ createSwitchedOnTemplateConnectorIn(orgId: string, actor: string | null, platformTemplateId: string, opts?: {
580
+ actorTokenId?: string;
581
+ auditDetail?: AuditDetail;
582
+ }): Promise<string | undefined>;
583
+ /**
584
+ * Records a connector made from one of the item's connector templates on the org's install of
585
+ * the item whose status is one of `statuses` (`created`: the plugin made it, so an uninstall and
586
+ * upgrades see it), in the caller's transaction. True when such an install exists.
587
+ */
588
+ recordTemplateConnectorIn(orgId: string, itemId: string, connectorId: string, templateId: string, statuses: readonly PluginInstallStatus[]): Promise<boolean>;
601
589
  /**
602
590
  * Records a connector made from a plugin's template on the org's live install of that plugin,
603
591
  * when there is one, under the org lock (so an uninstall in between is seen).
604
592
  */
605
593
  private recordOnLiveInstall;
594
+ /** The `connector@1` implementations loaded on this replica, by extension and kind. */
595
+ loadedConnectors(): {
596
+ plugin: string;
597
+ kind: string;
598
+ }[];
606
599
  /** The connector kinds an extension provides (the `connector@1` implementations loaded on this replica). */
607
600
  connectorKindsOf(plugin: string): string[];
608
601
  /**