@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
@@ -13,24 +13,28 @@ import { LockService } from "../infra/lock/lock.service.js";
13
13
  import { LockedCron } from "../infra/schedule/locked-cron.decorator.js";
14
14
  import { LockedInterval } from "../infra/schedule/locked-interval.js";
15
15
  import { KERNEL_LOGGER } from "../infra/tokens.js";
16
- import { MARKETPLACES_REFRESH_JOB, PLUGIN_STAGING_CLEANUP_JOB } from "./job-ids.js";
16
+ import { MARKETPLACES_REFRESH_JOB, PLUGIN_STAGING_CLEANUP_JOB, TEMPLATE_CONNECTORS_SWEEP_BATCH, TEMPLATE_CONNECTORS_SWEEP_JOB, TEMPLATE_CONNECTORS_SWEEP_PERIOD_MS, } from "./job-ids.js";
17
17
  import { MARKETPLACES_REFRESH_DEADLINE_MS, MarketplacesService } from "./marketplaces.service.js";
18
18
  import { PluginImport } from "./plugin-import.js";
19
+ import { TemplateConnectorEnsurer } from "./template-connector-ensure.js";
19
20
  /**
20
21
  * The catalog's periodic jobs, each run once per tick across replicas: the marketplace refresh
21
22
  * (`catalogs-refresh`, every `marketplaces.refreshIntervalMinutes` and once after the start:
22
- * `@LockedInterval` with `runOnStart`) and the
23
- * hourly cleanup of expired plugin import staging (`app-staging-cleanup`: `@LockedCron`).
23
+ * `@LockedInterval` with `runOnStart`), the
24
+ * hourly cleanup of expired plugin import staging (`app-staging-cleanup`: `@LockedCron`) and the
25
+ * template connector sweep (`template-connectors-sweep`, every five minutes: `@LockedInterval`).
24
26
  */
25
27
  let CatalogJobs = class CatalogJobs {
26
28
  marketplaces;
27
29
  imports;
30
+ templateConnectors;
28
31
  config;
29
32
  lockService;
30
33
  log;
31
- constructor(marketplaces, imports, config, lockService, log) {
34
+ constructor(marketplaces, imports, templateConnectors, config, lockService, log) {
32
35
  this.marketplaces = marketplaces;
33
36
  this.imports = imports;
37
+ this.templateConnectors = templateConnectors;
34
38
  this.config = config;
35
39
  this.lockService = lockService;
36
40
  this.log = log;
@@ -44,6 +48,19 @@ let CatalogJobs = class CatalogJobs {
44
48
  const deadline = AbortSignal.timeout(MARKETPLACES_REFRESH_DEADLINE_MS);
45
49
  await this.marketplaces.refreshAll(stop ? AbortSignal.any([deadline, stop]) : deadline);
46
50
  }
51
+ /**
52
+ * The backstop for template connectors no event re-triggers (ruling R30): a bounded batch of
53
+ * orgs whose missing template connector's kind is available now. Runs outside any transaction;
54
+ * each connector is created in its own (`TemplateConnectorEnsurer`).
55
+ */
56
+ async sweepTemplateConnectors(stop) {
57
+ const r = await this.templateConnectors.sweep({
58
+ limit: TEMPLATE_CONNECTORS_SWEEP_BATCH,
59
+ ...(stop !== undefined && { signal: stop }),
60
+ });
61
+ if (r.created > 0)
62
+ this.log.info("template connector sweep created connectors", r);
63
+ }
47
64
  /** Deletes expired staging rows and their objects. */
48
65
  async cleanupStaging() {
49
66
  const n = await this.imports.cleanupExpired();
@@ -56,6 +73,9 @@ __decorate([
56
73
  // a fresh deployment's marketplaces are refreshed right after the start
57
74
  { runOnStart: true })
58
75
  ], CatalogJobs.prototype, "refreshMarketplaces", null);
76
+ __decorate([
77
+ LockedInterval(TEMPLATE_CONNECTORS_SWEEP_JOB, () => TEMPLATE_CONNECTORS_SWEEP_PERIOD_MS)
78
+ ], CatalogJobs.prototype, "sweepTemplateConnectors", null);
59
79
  __decorate([
60
80
  LockedCron("0 * * * *", { name: PLUGIN_STAGING_CLEANUP_JOB })
61
81
  ], CatalogJobs.prototype, "cleanupStaging", null);
@@ -63,8 +83,9 @@ CatalogJobs = __decorate([
63
83
  Injectable(),
64
84
  __param(0, Inject(MarketplacesService)),
65
85
  __param(1, Inject(PluginImport)),
66
- __param(2, Inject(KernelConfigService)),
67
- __param(3, Inject(LockService)),
68
- __param(4, Inject(KERNEL_LOGGER))
86
+ __param(2, Inject(TemplateConnectorEnsurer)),
87
+ __param(3, Inject(KernelConfigService)),
88
+ __param(4, Inject(LockService)),
89
+ __param(5, Inject(KERNEL_LOGGER))
69
90
  ], CatalogJobs);
70
91
  export { CatalogJobs };
@@ -208,7 +208,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
208
208
  /** The host versions (an entry's `minKernel` is judged against them). */
209
209
  export declare const HOST_VERSIONS: {
210
210
  readonly kernel: string;
211
- readonly sdk: "0.1.0-rc.68";
211
+ readonly sdk: "0.1.0-rc.69";
212
212
  };
213
213
  /** Whether this deployment satisfies the entry's `minKernel`. */
214
214
  export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
@@ -11,20 +11,6 @@ import { CatalogGuideQuery, CatalogMarketplaceRequestBody, CatalogRequestBody, C
11
11
  import { OrgCatalogService } from "./org-catalog.service.js";
12
12
  import { PluginInstaller, type PluginInstallView, type UninstallPreview, type UninstallReport } from "./plugin-install.js";
13
13
  import { CatalogRequestsService, type CatalogRequestView } from "./requests.service.js";
14
- declare const ConnectorsBody: z.ZodObject<{
15
- inputs: z.ZodObject<{
16
- connectors: z.ZodRecord<z.ZodString, z.ZodObject<{
17
- name: z.ZodOptional<z.ZodString>;
18
- slug: z.ZodOptional<z.ZodString>;
19
- endpoint: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
20
- credential: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
21
- client: z.ZodOptional<z.ZodObject<{
22
- clientId: z.ZodString;
23
- clientSecret: z.ZodOptional<z.ZodString>;
24
- }, z.core.$strict>>;
25
- }, z.core.$strict>>;
26
- }, z.core.$strict>;
27
- }, z.core.$strict>;
28
14
  declare const TemplateConnectorBody: z.ZodObject<{
29
15
  name: z.ZodOptional<z.ZodString>;
30
16
  config: z.ZodObject<{
@@ -134,24 +120,10 @@ export declare class OrgCatalogController {
134
120
  confirm: string;
135
121
  }>;
136
122
  install(principal: Principal, org: OrgContext, itemId: string, body: z.infer<typeof OrgPluginInstallBody>, reply: FastifyReply): Promise<Omit<OrgInstallResult, "status">>;
137
- /**
138
- * Creates the connectors an installed plugin is missing (ruling P2-10: a connector template on
139
- * in the org without a connector there, e.g. added by a platform update; the plugin shows
140
- * `needs_config`): `{ inputs: { connectors: { <templateId>: input } } }` with the same input
141
- * checks as an install; recorded on the install -> 201 `{ connectors: [{ templateId,
142
- * connectorId }] }`. Not installed -> 404 `plugin.install_not_found`; a template not missing ->
143
- * 400 `validation_failed`.
144
- */
145
- configureConnectors(principal: Principal, org: OrgContext, itemId: string, body: z.infer<typeof ConnectorsBody>): Promise<{
146
- connectors: {
147
- templateId: string;
148
- connectorId: string;
149
- }[];
150
- }>;
151
123
  /**
152
124
  * One more connector from a platform connector template on in the org (rulings P4-7, P4-T6-8):
153
- * `{ name?, config: { slug?, endpoint?, credential?, client? } }` with the checks of an install
154
- * -> 201 `{ connector, issues }` (as `POST connectors`). A template not usable in the org -> 404
125
+ * `{ name?, config: { slug?, endpoint?, credential?, client? } }` (the org credential or OAuth
126
+ * client the template needs is required) -> 201 `{ connector, issues }` (as `POST connectors`). A template not usable in the org -> 404
155
127
  * `component.not_found`; off there -> 409 `component.off`; input errors -> 400 at `config.*`.
156
128
  */
157
129
  templateConnector(principal: Principal, org: OrgContext, templateId: string, body: z.infer<typeof TemplateConnectorBody>): Promise<{
@@ -16,11 +16,10 @@ import { createZodDto } from "../infra/validation/create-zod-dto.js";
16
16
  import { ZBody, ZQuery } from "../infra/validation/zod-params.js";
17
17
  import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
18
18
  import { roleAtLeast } from "../orgs/roles.js";
19
- import { CatalogGuideQuery, CatalogMarketplaceRequestBody, CatalogRequestBody, CatalogRequestsListQuery, NetworkRequestBody, OrgPluginConnectorsSchema, OrgPluginInstallBody, OrgPluginSwitchBody, OrgTemplateConnectorSchema, } from "./org-catalog.schemas.js";
19
+ import { CatalogGuideQuery, CatalogMarketplaceRequestBody, CatalogRequestBody, CatalogRequestsListQuery, NetworkRequestBody, OrgPluginInstallBody, OrgPluginSwitchBody, OrgTemplateConnectorSchema, } from "./org-catalog.schemas.js";
20
20
  import { OrgCatalogService } from "./org-catalog.service.js";
21
21
  import { PluginInstaller, } from "./plugin-install.js";
22
22
  import { CatalogRequestsService } from "./requests.service.js";
23
- const ConnectorsBody = OrgPluginConnectorsSchema;
24
23
  const TemplateConnectorBody = OrgTemplateConnectorSchema;
25
24
  /**
26
25
  * 条目图标的响应头:图标可能是 SVG(可含脚本),只许网页以 `<img>` 显示;直接打开时 CSP sandbox 禁止脚本与一切外部
@@ -45,8 +44,6 @@ class CatalogDecideBody extends createZodDto(DecideBody, "CatalogDecideBody") {
45
44
  }
46
45
  class OrgPluginInstallBodyDto extends createZodDto(OrgPluginInstallBody, "OrgPluginInstallBody") {
47
46
  }
48
- class OrgPluginConnectorsBody extends createZodDto(ConnectorsBody, "OrgPluginConnectorsBody") {
49
- }
50
47
  class OrgPluginSwitchBodyDto extends createZodDto(OrgPluginSwitchBody, "OrgPluginSwitchBody") {
51
48
  }
52
49
  class OrgTemplateConnectorBody extends createZodDto(TemplateConnectorBody, "OrgTemplateConnectorBody") {
@@ -180,25 +177,10 @@ let OrgCatalogController = class OrgCatalogController {
180
177
  const { status: _status, ...rest } = r;
181
178
  return rest;
182
179
  }
183
- /**
184
- * Creates the connectors an installed plugin is missing (ruling P2-10: a connector template on
185
- * in the org without a connector there, e.g. added by a platform update; the plugin shows
186
- * `needs_config`): `{ inputs: { connectors: { <templateId>: input } } }` with the same input
187
- * checks as an install; recorded on the install -> 201 `{ connectors: [{ templateId,
188
- * connectorId }] }`. Not installed -> 404 `plugin.install_not_found`; a template not missing ->
189
- * 400 `validation_failed`.
190
- */
191
- async configureConnectors(principal, org, itemId, body) {
192
- const p = requireUser(principal);
193
- const tokenId = patTokenId(p);
194
- return {
195
- connectors: await this.pluginInstaller.configureConnectors(org.orgId, p.account.id, itemId, body.inputs, tokenId !== undefined ? { actorTokenId: tokenId } : {}),
196
- };
197
- }
198
180
  /**
199
181
  * One more connector from a platform connector template on in the org (rulings P4-7, P4-T6-8):
200
- * `{ name?, config: { slug?, endpoint?, credential?, client? } }` with the checks of an install
201
- * -> 201 `{ connector, issues }` (as `POST connectors`). A template not usable in the org -> 404
182
+ * `{ name?, config: { slug?, endpoint?, credential?, client? } }` (the org credential or OAuth
183
+ * client the template needs is required) -> 201 `{ connector, issues }` (as `POST connectors`). A template not usable in the org -> 404
202
184
  * `component.not_found`; off there -> 409 `component.off`; input errors -> 400 at `config.*`.
203
185
  */
204
186
  async templateConnector(principal, org, templateId, body) {
@@ -308,14 +290,6 @@ __decorate([
308
290
  __param(3, ZBody(OrgPluginInstallBodyDto)),
309
291
  __param(4, Res({ passthrough: true }))
310
292
  ], OrgCatalogController.prototype, "install", null);
311
- __decorate([
312
- Post("catalog/:itemId/connectors"),
313
- OrgAction("connectors.manage"),
314
- __param(0, CurrentPrincipal()),
315
- __param(1, CurrentOrg()),
316
- __param(2, Param("itemId")),
317
- __param(3, ZBody(OrgPluginConnectorsBody))
318
- ], OrgCatalogController.prototype, "configureConnectors", null);
319
293
  __decorate([
320
294
  Post("connector-templates/:templateId/connectors"),
321
295
  OrgAction("connectors.manage"),
@@ -28,8 +28,8 @@ export declare const CatalogMarketplaceRequestBody: z.ZodObject<{
28
28
  note: z.ZodOptional<z.ZodString>;
29
29
  }, z.core.$strict>;
30
30
  /**
31
- * One connector template's input at install (C30): name, slug, endpoint, credential or OAuth
32
- * client. The credential and the client secret are secrets (`secret()` meta, ruling R2): a Platform
31
+ * One connector template's input for one more connector from it (C30): name, slug, endpoint,
32
+ * credential or OAuth client. The credential and the client secret are secrets (`secret()` meta, ruling R2): a Platform
33
33
  * operation never takes them as params; the person enters them in a secure input request.
34
34
  */
35
35
  export declare const CatalogConnectorInput: z.ZodObject<{
@@ -43,43 +43,16 @@ export declare const CatalogConnectorInput: z.ZodObject<{
43
43
  }, z.core.$strict>>;
44
44
  }, z.core.$strict>;
45
45
  /**
46
- * The org install body: template input, and the connector templates the org chose to switch on
47
- * (`templatesOn`: exactly these are on after the install and make connectors, the plugin's other
48
- * templates are switched off in the org and stay available on the connectors page; absent: the
49
- * templates on in the org now). No version: an org installs the platform version (one per
50
- * deployment, ruling P2-17).
46
+ * The org install body: the connector templates the org chose to switch on (`templatesOn`: exactly
47
+ * these are on after the install and make connectors, the plugin's other templates are switched off
48
+ * in the org and stay available on the connectors page; absent: the templates on in the org now).
49
+ * No connector input (plugin pages spec §5.2.2): a template that needs an org credential or OAuth
50
+ * client becomes a `needs_config` connector. No version: an org installs the platform version
51
+ * (one per deployment, ruling P2-17).
51
52
  */
52
53
  export declare const OrgPluginInstallBody: z.ZodObject<{
53
- connectors: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
54
- name: z.ZodOptional<z.ZodString>;
55
- slug: z.ZodOptional<z.ZodString>;
56
- endpoint: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
57
- credential: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
58
- client: z.ZodOptional<z.ZodObject<{
59
- clientId: z.ZodString;
60
- clientSecret: z.ZodOptional<z.ZodString>;
61
- }, z.core.$strict>>;
62
- }, z.core.$strict>>>;
63
54
  templatesOn: z.ZodOptional<z.ZodArray<z.ZodString>>;
64
55
  }, z.core.$strict>;
65
- /**
66
- * `POST …/catalog/:itemId/connectors` (ruling P2-10): the input of missing connectors, by template
67
- * id, as at install.
68
- */
69
- export declare const OrgPluginConnectorsSchema: z.ZodObject<{
70
- inputs: z.ZodObject<{
71
- connectors: z.ZodRecord<z.ZodString, z.ZodObject<{
72
- name: z.ZodOptional<z.ZodString>;
73
- slug: z.ZodOptional<z.ZodString>;
74
- endpoint: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
75
- credential: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
76
- client: z.ZodOptional<z.ZodObject<{
77
- clientId: z.ZodString;
78
- clientSecret: z.ZodOptional<z.ZodString>;
79
- }, z.core.$strict>>;
80
- }, z.core.$strict>>;
81
- }, z.core.$strict>;
82
- }, z.core.$strict>;
83
56
  /**
84
57
  * `POST …/connector-templates/:templateId/connectors` (ruling P4-T6-8): one more connector from a
85
58
  * platform connector template, its name and an install's connector input (`config`).
@@ -100,20 +73,10 @@ export declare const OrgTemplateConnectorSchema: z.ZodObject<{
100
73
  export declare const ConnectorTemplatePathParams: z.ZodObject<{
101
74
  templateId: z.ZodString;
102
75
  }, z.core.$strip>;
103
- /** The switch body: on (with the install inputs), or off (with the preview's hash to confirm). */
76
+ /** The switch body: on (with the install choice), or off (with the preview's hash to confirm). */
104
77
  export declare const OrgPluginSwitchBody: z.ZodObject<{
105
78
  enabled: z.ZodBoolean;
106
79
  inputs: z.ZodOptional<z.ZodObject<{
107
- connectors: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
108
- name: z.ZodOptional<z.ZodString>;
109
- slug: z.ZodOptional<z.ZodString>;
110
- endpoint: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
111
- credential: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
112
- client: z.ZodOptional<z.ZodObject<{
113
- clientId: z.ZodString;
114
- clientSecret: z.ZodOptional<z.ZodString>;
115
- }, z.core.$strict>>;
116
- }, z.core.$strict>>>;
117
80
  templatesOn: z.ZodOptional<z.ZodArray<z.ZodString>>;
118
81
  }, z.core.$strict>>;
119
82
  confirm: z.ZodOptional<z.ZodString>;
@@ -50,8 +50,8 @@ export const CatalogMarketplaceRequestBody = z
50
50
  })
51
51
  .strict();
52
52
  /**
53
- * One connector template's input at install (C30): name, slug, endpoint, credential or OAuth
54
- * client. The credential and the client secret are secrets (`secret()` meta, ruling R2): a Platform
53
+ * One connector template's input for one more connector from it (C30): name, slug, endpoint,
54
+ * credential or OAuth client. The credential and the client secret are secrets (`secret()` meta, ruling R2): a Platform
55
55
  * operation never takes them as params; the person enters them in a secure input request.
56
56
  */
57
57
  export const CatalogConnectorInput = z
@@ -70,27 +70,18 @@ export const CatalogConnectorInput = z
70
70
  })
71
71
  .strict();
72
72
  /**
73
- * The org install body: template input, and the connector templates the org chose to switch on
74
- * (`templatesOn`: exactly these are on after the install and make connectors, the plugin's other
75
- * templates are switched off in the org and stay available on the connectors page; absent: the
76
- * templates on in the org now). No version: an org installs the platform version (one per
77
- * deployment, ruling P2-17).
73
+ * The org install body: the connector templates the org chose to switch on (`templatesOn`: exactly
74
+ * these are on after the install and make connectors, the plugin's other templates are switched off
75
+ * in the org and stay available on the connectors page; absent: the templates on in the org now).
76
+ * No connector input (plugin pages spec §5.2.2): a template that needs an org credential or OAuth
77
+ * client becomes a `needs_config` connector. No version: an org installs the platform version
78
+ * (one per deployment, ruling P2-17).
78
79
  */
79
80
  export const OrgPluginInstallBody = z
80
81
  .object({
81
- connectors: z.record(z.string(), CatalogConnectorInput).optional(),
82
82
  templatesOn: z.array(z.string().min(1).max(100)).max(50).optional(),
83
83
  })
84
84
  .strict();
85
- /**
86
- * `POST …/catalog/:itemId/connectors` (ruling P2-10): the input of missing connectors, by template
87
- * id, as at install.
88
- */
89
- export const OrgPluginConnectorsSchema = z
90
- .object({
91
- inputs: z.object({ connectors: z.record(z.string(), CatalogConnectorInput) }).strict(),
92
- })
93
- .strict();
94
85
  /**
95
86
  * `POST …/connector-templates/:templateId/connectors` (ruling P4-T6-8): one more connector from a
96
87
  * platform connector template, its name and an install's connector input (`config`).
@@ -103,7 +94,7 @@ export const OrgTemplateConnectorSchema = z
103
94
  .strict();
104
95
  /** `:templateId` of the template connector route (`@Param`). */
105
96
  export const ConnectorTemplatePathParams = z.object({ templateId: z.string().min(1) });
106
- /** The switch body: on (with the install inputs), or off (with the preview's hash to confirm). */
97
+ /** The switch body: on (with the install choice), or off (with the preview's hash to confirm). */
107
98
  export const OrgPluginSwitchBody = z
108
99
  .object({
109
100
  enabled: z.boolean(),
@@ -163,11 +154,6 @@ export const ORG_CATALOG_ROUTES = [
163
154
  params: CatalogItemPathParams,
164
155
  body: OrgPluginInstallBody,
165
156
  },
166
- {
167
- route: "POST /api/v1/orgs/:orgId/catalog/:itemId/connectors",
168
- params: CatalogItemPathParams,
169
- body: OrgPluginConnectorsSchema,
170
- },
171
157
  {
172
158
  route: "POST /api/v1/orgs/:orgId/connector-templates/:templateId/connectors",
173
159
  params: ConnectorTemplatePathParams,
@@ -24,7 +24,7 @@ import { packagePath } from "../packages/tgz.js";
24
24
  import { StorageService } from "../storage/storage.service.js";
25
25
  import { catalogHasIcon, findConnectorIn, orgTemplateView, readCatalogIcon, readCatalogTemplates, templatePluginProblem, } from "./catalog-content.js";
26
26
  import { itemView, ownerOnlyFacts, versionUsable } from "./catalog-items.js";
27
- import { connectorTemplatesOn, templateIdOfPath } from "./component-state.js";
27
+ import { connectorTemplatesOn } from "./component-state.js";
28
28
  import { LIVE_INSTALL_STATUSES } from "./install-status.js";
29
29
  import { itemPendingError, ownerOf, ownersOf } from "./ownership.js";
30
30
  import { PluginInstaller, uninstallPreviewHash, upsertOrgSwitch, } from "./plugin-install.js";
@@ -187,6 +187,11 @@ let OrgCatalogService = class OrgCatalogService {
187
187
  let reason;
188
188
  const extName = extensionOf(i);
189
189
  const why = extName === undefined ? undefined : unloaded.get(extName);
190
+ // The plugin's own `needs_config` (plugin pages spec §5.2.3): its extension, loaded here, has
191
+ // no valid effective config for the org; connector setup shows on the connector cards
192
+ const configInvalid = async () => extName !== undefined &&
193
+ loaded.has(extName) &&
194
+ !(await this.effective.get(orgId, extName)).ok;
190
195
  if (i.awaiting_confirmation)
191
196
  state = "awaiting_confirmation";
192
197
  else if (i.disabled) {
@@ -202,26 +207,17 @@ let OrgCatalogService = class OrgCatalogService {
202
207
  reason = why.reason;
203
208
  }
204
209
  else if (a) {
205
- // An on connector template without a connector here (ruling P2-10)
206
- const missing = await this.pluginInstaller.missingConnectors(orgId, i.id);
207
- state = (missing?.templates.length ?? 0) > 0 ? "needs_config" : "on";
210
+ state = (await configInvalid()) ? "needs_config" : "on";
208
211
  }
209
212
  else if (i.builtin)
210
213
  state = "on";
211
214
  else if (!wanted)
212
215
  state = "off";
213
216
  else {
214
- const m = latest?.manifest;
215
- const ext = m?.extension ? loaded.get(m.name) : undefined;
216
- // only the connector templates on in the org need input (ruling P2-6)
217
- const templateIds = (m?.connectorTemplates ?? []).map((t) => templateIdOfPath(t.path));
218
- const needsInputs = (await connectorTemplatesOn(this.db, orgId, i.id, templateIds)).size > 0 ||
219
- (m?.extension !== undefined &&
220
- ext !== undefined &&
221
- !(await this.effective.get(orgId, m.name)).ok);
222
- // Wanted but not installed and needing nothing: the sync has not installed it (yet, or its
223
- // install failed); `off`, so an org admin can switch it on (the worker start retries it)
224
- state = needsInputs ? "needs_config" : "off";
217
+ // Wanted but not installed: the sync has not installed it (yet, or its install failed);
218
+ // `off`, so an org admin can switch it on (the worker start retries it), unless its
219
+ // extension's effective config is not valid here
220
+ state = (await configInvalid()) ? "needs_config" : "off";
225
221
  }
226
222
  out.push({
227
223
  ...view,
@@ -278,7 +274,7 @@ let OrgCatalogService = class OrgCatalogService {
278
274
  throw itemNotFound();
279
275
  const m = v.manifest;
280
276
  const templates = await readCatalogTemplates(this.storage, v);
281
- // Which templates are on in this org now: the install asks for the input of those, a
277
+ // Which templates are on in this org now: the install makes connectors of those, a
282
278
  // default-off one an admin switched on included
283
279
  const on = await connectorTemplatesOn(this.db, orgId, itemId, templates.map((t) => t.id));
284
280
  // Where each template's page finds its setup guide (spec 2026-11-09-setup-guides-v2 §9.3)
@@ -286,8 +282,7 @@ let OrgCatalogService = class OrgCatalogService {
286
282
  const g = templateGuideOf(m, templateId);
287
283
  return g ? { itemId, guideId: g.id } : null;
288
284
  };
289
- // A template whose connector an earlier switch-off kept: the install reuses it, so the wizard
290
- // does not ask for its input
285
+ // A template whose connector an earlier switch-off kept: the install reuses it
291
286
  const connected = await this.pluginInstaller.connectedTemplates(orgId, itemId);
292
287
  // Providers the install would switch on first (a refusal is the install's to report)
293
288
  const implied = await this.pluginInstaller
@@ -297,11 +292,8 @@ let OrgCatalogService = class OrgCatalogService {
297
292
  return [];
298
293
  throw e;
299
294
  });
300
- const missing = item.installed !== null && item.state === "needs_config"
301
- ? ((await this.pluginInstaller.missingConnectors(orgId, itemId))?.templates ?? [])
302
- : [];
303
295
  // Each template's icon on the org's routes (its own, else the plugin's)
304
- const icons = await this.icons.ofItemTemplates(itemId, [...templates, ...missing].map((t) => t.id), { kind: "org", orgId, isAdmin: await this.isOrgAdmin(orgId, accountId) });
296
+ const icons = await this.icons.ofItemTemplates(itemId, templates.map((t) => t.id), { kind: "org", orgId, isAdmin: await this.isOrgAdmin(orgId, accountId) });
305
297
  const iconOf = (templateId) => icons.get(templateId) ?? null;
306
298
  return {
307
299
  item,
@@ -319,7 +311,6 @@ let OrgCatalogService = class OrgCatalogService {
319
311
  ],
320
312
  skills: (m.skills ?? []).map((s) => packagePath(s.path)),
321
313
  agents: (m.agents ?? []).map((a) => packagePath(a.path)),
322
- missingTemplates: missing.map((t) => orgTemplateView(t.id, t.file, { guide: guideOf(t.id), on: true, icon: iconOf(t.id) })),
323
314
  };
324
315
  }
325
316
  /**
@@ -138,6 +138,12 @@ export interface PluginReviewTemplate {
138
138
  editableEndpoint: string[];
139
139
  /** The connector is loaded on this replica and the endpoint was checked against its schema. */
140
140
  endpointChecked: boolean;
141
+ /**
142
+ * The template's own icon from the package as a `data:` URL (svg or png, at most
143
+ * 64 KiB), null without one. Nothing serves a staged package's files, so
144
+ * the review carries it; display only, not part of {@link pluginReviewHash}.
145
+ */
146
+ icon: string | null;
141
147
  }
142
148
  /** One agent template in a review (sub-agents spec §16.2: its tool narrowing and model tier). */
143
149
  export interface PluginReviewAgentTemplate {
@@ -155,7 +161,22 @@ export interface PluginReviewAgentTemplate {
155
161
  effort?: AgentTemplate["effort"];
156
162
  maxSteps?: number;
157
163
  skills?: string[];
164
+ /**
165
+ * The connectors the agent needs, from its definition: a connector template id (`<id>` or
166
+ * `<plugin>:<id>`), or a described need with its label, endpoint and protocol; [] without any.
167
+ */
168
+ connectors: PluginReviewAgentConnector[];
158
169
  }
170
+ /** One connector an agent template needs, as its review shows it. */
171
+ export type PluginReviewAgentConnector = {
172
+ template: string;
173
+ } | {
174
+ needs: {
175
+ label: string;
176
+ endpoint: string;
177
+ protocol: "mcp" | "openapi";
178
+ };
179
+ };
159
180
  /** One theme in a review (themes spec §6): what the super admin sees before confirming. */
160
181
  export interface PluginReviewTheme {
161
182
  /** The theme id (the file's base name). */
@@ -38,7 +38,7 @@ import { Transactional } from "../infra/database/transactional.decorator.js";
38
38
  import { OutboxService } from "../infra/outbox/outbox.service.js";
39
39
  import { KERNEL_LOGGER } from "../infra/tokens.js";
40
40
  import { OrgLock } from "../orgs/org-lock.js";
41
- import { packPackageTgz } from "../packages/tgz.js";
41
+ import { packagePath, packPackageTgz } from "../packages/tgz.js";
42
42
  import { checkSkillFiles, SkillArchiveError } from "../skills/package.js";
43
43
  import { StorageService } from "../storage/storage.service.js";
44
44
  import { canonicalJson } from "../tools/canonical-json.js";
@@ -1546,12 +1546,29 @@ let PluginImport = class PluginImport {
1546
1546
  auth: t.auth,
1547
1547
  editableEndpoint: t.editableEndpoint ?? [],
1548
1548
  endpointChecked: loaded !== undefined,
1549
+ icon: reviewIcon(c.file.icon, pkg.files),
1549
1550
  };
1550
1551
  });
1551
1552
  const agentTemplates = pkg.agentTemplates.map((a) => {
1552
1553
  keepObject(a.path);
1553
- const { name, description, instructions, model, ...rest } = a.template;
1554
- return { name, path: a.path, description, instructions, model: model ?? "inherit", ...rest };
1554
+ const { name, description, instructions, model, connectors, ...rest } = a.template;
1555
+ return {
1556
+ name,
1557
+ path: a.path,
1558
+ description,
1559
+ instructions,
1560
+ model: model ?? "inherit",
1561
+ ...rest,
1562
+ connectors: (connectors ?? []).map((c) => "template" in c
1563
+ ? { template: c.template }
1564
+ : {
1565
+ needs: {
1566
+ label: c.needs.label,
1567
+ endpoint: c.needs.endpoint,
1568
+ protocol: c.needs.protocol,
1569
+ },
1570
+ }),
1571
+ };
1555
1572
  });
1556
1573
  // Themes: the file as written, the assets as sanitized by the reader (never the uploaded
1557
1574
  // originals: a shared path, e.g. the plugin icon, is stored sanitized too)
@@ -1840,6 +1857,19 @@ export function pluginReviewHash(r, files) {
1840
1857
  ]);
1841
1858
  return createHash("sha256").update(canonical).digest("hex").slice(0, 32);
1842
1859
  }
1860
+ /**
1861
+ * A connector template's icon (package path `icon`) as a `data:` URL for its review, null without
1862
+ * one. The package reader checked it is an svg or png within the size limit.
1863
+ */
1864
+ function reviewIcon(icon, files) {
1865
+ if (icon === undefined)
1866
+ return null;
1867
+ const data = files.get(packagePath(icon));
1868
+ if (data === undefined)
1869
+ return null;
1870
+ const type = /\.png$/i.test(icon) ? "image/png" : "image/svg+xml";
1871
+ return `data:${type};base64,${Buffer.from(data).toString("base64")}`;
1872
+ }
1843
1873
  /** The client code of a read extension package for its review (sizes from the package's files). */
1844
1874
  function reviewClient(pkg) {
1845
1875
  const c = pkg.section.client;