@capybara-hq/kernel 0.1.0-rc.58 → 0.1.0-rc.59

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 (86) hide show
  1. package/dist/catalog/marketplaces.service.d.ts +1 -1
  2. package/dist/catalog/org-catalog.controller.d.ts +0 -5
  3. package/dist/catalog/org-catalog.controller.js +3 -17
  4. package/dist/catalog/org-catalog.schemas.d.ts +43 -0
  5. package/dist/catalog/org-catalog.schemas.js +43 -2
  6. package/dist/catalog/plugin-install.d.ts +2 -0
  7. package/dist/catalog/plugin-install.js +3 -3
  8. package/dist/channels/channels.schemas.d.ts +3 -0
  9. package/dist/channels/channels.schemas.js +8 -0
  10. package/dist/channels/connections.service.d.ts +17 -2
  11. package/dist/channels/connections.service.js +30 -5
  12. package/dist/channels/outbound.js +17 -0
  13. package/dist/conversations/events.d.ts +34 -0
  14. package/dist/conversations/events.js +24 -0
  15. package/dist/ctx/secrets.d.ts +8 -1
  16. package/dist/ctx/secrets.js +14 -1
  17. package/dist/db/kernel-schema.d.ts +19 -0
  18. package/dist/devices/working-root.d.ts +2 -3
  19. package/dist/errors.d.ts +10 -0
  20. package/dist/errors.js +10 -0
  21. package/dist/http/api.module.js +6 -0
  22. package/dist/identity/initial-passwords.job.d.ts +3 -3
  23. package/dist/identity/initial-passwords.job.js +7 -5
  24. package/dist/orgs/invitations.controller.d.ts +3 -11
  25. package/dist/orgs/invitations.controller.js +9 -10
  26. package/dist/orgs/invitations.service.d.ts +12 -2
  27. package/dist/orgs/invitations.service.js +14 -7
  28. package/dist/orgs/members.service.d.ts +12 -2
  29. package/dist/orgs/members.service.js +10 -8
  30. package/dist/orgs/orgs.controller.d.ts +4 -12
  31. package/dist/orgs/orgs.controller.js +10 -10
  32. package/dist/orgs/orgs.schemas.d.ts +26 -0
  33. package/dist/orgs/orgs.schemas.js +22 -0
  34. package/dist/platform/connector-person-fields.d.ts +67 -0
  35. package/dist/platform/connector-person-fields.js +129 -0
  36. package/dist/platform/exclusions.js +5 -100
  37. package/dist/platform/operation.d.ts +31 -0
  38. package/dist/platform/operation.js +3 -3
  39. package/dist/platform/ops/accounts.ops.js +1 -0
  40. package/dist/platform/ops/channels.ops.d.ts +10 -3
  41. package/dist/platform/ops/channels.ops.js +223 -5
  42. package/dist/platform/ops/connectors.ops.d.ts +22 -4
  43. package/dist/platform/ops/connectors.ops.js +664 -13
  44. package/dist/platform/ops/org-plugins.ops.d.ts +15 -2
  45. package/dist/platform/ops/org-plugins.ops.js +323 -4
  46. package/dist/platform/ops/orgs.ops.d.ts +40 -3
  47. package/dist/platform/ops/orgs.ops.js +293 -12
  48. package/dist/platform/ops/person-inputs.d.ts +30 -0
  49. package/dist/platform/ops/person-inputs.js +50 -0
  50. package/dist/platform/ops/plugins.ops.d.ts +1 -1
  51. package/dist/platform/ops/plugins.ops.js +6 -6
  52. package/dist/platform/parity.d.ts +3 -2
  53. package/dist/platform/parity.js +40 -15
  54. package/dist/platform/person-fields.d.ts +20 -4
  55. package/dist/platform/person-fields.js +27 -5
  56. package/dist/platform/platform.module.d.ts +2 -1
  57. package/dist/platform/platform.module.js +5 -3
  58. package/dist/platform/route-schemas.js +2 -0
  59. package/dist/platform/sealed-reveals.controller.d.ts +20 -0
  60. package/dist/platform/sealed-reveals.controller.js +48 -0
  61. package/dist/platform/sealed-reveals.d.ts +52 -0
  62. package/dist/platform/sealed-reveals.js +153 -0
  63. package/dist/runtime/project/knowledge.js +24 -19
  64. package/dist/sandbox/permission-facts.d.ts +5 -1
  65. package/dist/sandbox/permission-facts.js +8 -2
  66. package/dist/setup/setup-guides.service.d.ts +5 -0
  67. package/dist/setup/setup-guides.service.js +2 -1
  68. package/dist/tools/approvals.service.js +1 -1
  69. package/dist/tools/builtins/platform.js +48 -8
  70. package/dist/tools/connectors.controller.d.ts +6 -7
  71. package/dist/tools/connectors.controller.js +4 -44
  72. package/dist/tools/connectors.schemas.d.ts +170 -1
  73. package/dist/tools/connectors.schemas.js +82 -3
  74. package/dist/tools/connectors.service.d.ts +16 -6
  75. package/dist/tools/connectors.service.js +39 -24
  76. package/dist/tools/oauth/oauth.controller.d.ts +3 -6
  77. package/dist/tools/oauth/oauth.controller.js +3 -12
  78. package/dist/tools/oauth/oauth.schemas.d.ts +14 -0
  79. package/dist/tools/oauth/oauth.schemas.js +27 -0
  80. package/dist/tools/pipeline.d.ts +7 -0
  81. package/dist/tools/pipeline.js +13 -4
  82. package/dist/tools/policy.d.ts +3 -2
  83. package/dist/tools/policy.js +4 -2
  84. package/dist/tools/registry.d.ts +7 -0
  85. package/package.json +4 -4
  86. package/src/migrations/0170_platform_sealed_reveals.sql +27 -0
@@ -188,7 +188,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
188
188
  /** The host versions (an entry's `minKernel` is judged against them). */
189
189
  export declare const HOST_VERSIONS: {
190
190
  readonly kernel: string;
191
- readonly sdk: "0.1.0-rc.42";
191
+ readonly sdk: "0.1.0-rc.43";
192
192
  };
193
193
  /** Whether this deployment satisfies the entry's `minKernel`. */
194
194
  export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
@@ -11,7 +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
- /** The connectors body (ruling P2-10): the input of missing connectors, by template id, as at install. */
15
14
  declare const ConnectorsBody: z.ZodObject<{
16
15
  inputs: z.ZodObject<{
17
16
  connectors: z.ZodRecord<z.ZodString, z.ZodObject<{
@@ -26,10 +25,6 @@ declare const ConnectorsBody: z.ZodObject<{
26
25
  }, z.core.$strict>>;
27
26
  }, z.core.$strict>;
28
27
  }, z.core.$strict>;
29
- /**
30
- * One more connector from a platform connector template (ruling P4-T6-8): its name and an
31
- * install's connector input (`config`).
32
- */
33
28
  declare const TemplateConnectorBody: z.ZodObject<{
34
29
  name: z.ZodOptional<z.ZodString>;
35
30
  config: z.ZodObject<{
@@ -16,26 +16,12 @@ 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 { CatalogConnectorInput, CatalogGuideQuery, CatalogMarketplaceRequestBody, CatalogRequestBody, CatalogRequestsListQuery, NetworkRequestBody, OrgPluginInstallBody, OrgPluginSwitchBody, } from "./org-catalog.schemas.js";
19
+ import { CatalogGuideQuery, CatalogMarketplaceRequestBody, CatalogRequestBody, CatalogRequestsListQuery, NetworkRequestBody, OrgPluginConnectorsSchema, 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
- /** The connectors body (ruling P2-10): the input of missing connectors, by template id, as at install. */
24
- const ConnectorsBody = z
25
- .object({
26
- inputs: z.object({ connectors: z.record(z.string(), CatalogConnectorInput) }).strict(),
27
- })
28
- .strict();
29
- /**
30
- * One more connector from a platform connector template (ruling P4-T6-8): its name and an
31
- * install's connector input (`config`).
32
- */
33
- const TemplateConnectorBody = z
34
- .object({
35
- name: z.string().trim().min(1).max(80).optional(),
36
- config: CatalogConnectorInput.omit({ name: true }),
37
- })
38
- .strict();
23
+ const ConnectorsBody = OrgPluginConnectorsSchema;
24
+ const TemplateConnectorBody = OrgTemplateConnectorSchema;
39
25
  /**
40
26
  * 条目图标的响应头:图标可能是 SVG(可含脚本),只许网页以 `<img>` 显示;直接打开时 CSP sandbox 禁止脚本与一切外部
41
27
  * 请求,nosniff 防浏览器按内容另行判型。
@@ -27,6 +27,11 @@ export declare const CatalogMarketplaceRequestBody: z.ZodObject<{
27
27
  version: z.ZodString;
28
28
  note: z.ZodOptional<z.ZodString>;
29
29
  }, z.core.$strict>;
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
33
+ * operation never takes them as params; the person enters them on the confirmation card.
34
+ */
30
35
  export declare const CatalogConnectorInput: z.ZodObject<{
31
36
  name: z.ZodOptional<z.ZodString>;
32
37
  slug: z.ZodOptional<z.ZodString>;
@@ -54,6 +59,44 @@ export declare const OrgPluginInstallBody: z.ZodObject<{
54
59
  }, z.core.$strict>>>;
55
60
  extensionConfig: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
56
61
  }, z.core.$strict>;
62
+ /**
63
+ * `POST …/catalog/:itemId/connectors` (ruling P2-10): the input of missing connectors, by template
64
+ * id, as at install.
65
+ */
66
+ export declare const OrgPluginConnectorsSchema: z.ZodObject<{
67
+ inputs: z.ZodObject<{
68
+ connectors: z.ZodRecord<z.ZodString, z.ZodObject<{
69
+ name: z.ZodOptional<z.ZodString>;
70
+ slug: z.ZodOptional<z.ZodString>;
71
+ endpoint: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
72
+ credential: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
73
+ client: z.ZodOptional<z.ZodObject<{
74
+ clientId: z.ZodString;
75
+ clientSecret: z.ZodOptional<z.ZodString>;
76
+ }, z.core.$strict>>;
77
+ }, z.core.$strict>>;
78
+ }, z.core.$strict>;
79
+ }, z.core.$strict>;
80
+ /**
81
+ * `POST …/connector-templates/:templateId/connectors` (ruling P4-T6-8): one more connector from a
82
+ * platform connector template, its name and an install's connector input (`config`).
83
+ */
84
+ export declare const OrgTemplateConnectorSchema: z.ZodObject<{
85
+ name: z.ZodOptional<z.ZodString>;
86
+ config: z.ZodObject<{
87
+ slug: z.ZodOptional<z.ZodString>;
88
+ endpoint: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
89
+ credential: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
90
+ client: z.ZodOptional<z.ZodObject<{
91
+ clientId: z.ZodString;
92
+ clientSecret: z.ZodOptional<z.ZodString>;
93
+ }, z.core.$strict>>;
94
+ }, z.core.$strict>;
95
+ }, z.core.$strict>;
96
+ /** `:templateId` of the template connector route (`@Param`). */
97
+ export declare const ConnectorTemplatePathParams: z.ZodObject<{
98
+ templateId: z.ZodString;
99
+ }, z.core.$strip>;
57
100
  /** The switch body: on (with the install inputs), or off (with the preview's hash to confirm). */
58
101
  export declare const OrgPluginSwitchBody: z.ZodObject<{
59
102
  enabled: z.ZodBoolean;
@@ -1,4 +1,4 @@
1
- import { validateAllowHost } from "@capybara-hq/plugin-sdk";
1
+ import { secret, validateAllowHost } from "@capybara-hq/plugin-sdk";
2
2
  import { z } from "zod";
3
3
  import { CredentialValue } from "../tools/connectors.schemas.js";
4
4
  export const CatalogRequestBody = z
@@ -49,6 +49,11 @@ export const CatalogMarketplaceRequestBody = z
49
49
  note: z.string().max(1000).optional(),
50
50
  })
51
51
  .strict();
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
55
+ * operation never takes them as params; the person enters them on the confirmation card.
56
+ */
52
57
  export const CatalogConnectorInput = z
53
58
  .object({
54
59
  name: z.string().trim().min(1).max(80).optional(),
@@ -58,7 +63,7 @@ export const CatalogConnectorInput = z
58
63
  client: z
59
64
  .object({
60
65
  clientId: z.string().min(1).max(500),
61
- clientSecret: z.string().min(1).max(4000).optional(),
66
+ clientSecret: secret(z.string().min(1).max(4000)).optional(),
62
67
  })
63
68
  .strict()
64
69
  .optional(),
@@ -74,6 +79,27 @@ export const OrgPluginInstallBody = z
74
79
  extensionConfig: z.record(z.string(), z.unknown()).optional(),
75
80
  })
76
81
  .strict();
82
+ /**
83
+ * `POST …/catalog/:itemId/connectors` (ruling P2-10): the input of missing connectors, by template
84
+ * id, as at install.
85
+ */
86
+ export const OrgPluginConnectorsSchema = z
87
+ .object({
88
+ inputs: z.object({ connectors: z.record(z.string(), CatalogConnectorInput) }).strict(),
89
+ })
90
+ .strict();
91
+ /**
92
+ * `POST …/connector-templates/:templateId/connectors` (ruling P4-T6-8): one more connector from a
93
+ * platform connector template, its name and an install's connector input (`config`).
94
+ */
95
+ export const OrgTemplateConnectorSchema = z
96
+ .object({
97
+ name: z.string().trim().min(1).max(80).optional(),
98
+ config: CatalogConnectorInput.omit({ name: true }),
99
+ })
100
+ .strict();
101
+ /** `:templateId` of the template connector route (`@Param`). */
102
+ export const ConnectorTemplatePathParams = z.object({ templateId: z.string().min(1) });
77
103
  /** The switch body: on (with the install inputs), or off (with the preview's hash to confirm). */
78
104
  export const OrgPluginSwitchBody = z
79
105
  .object({
@@ -127,6 +153,21 @@ export const ORG_CATALOG_ROUTES = [
127
153
  body: CatalogRequestBody,
128
154
  },
129
155
  { route: "POST /api/v1/orgs/:orgId/marketplace-requests", body: CatalogMarketplaceRequestBody },
156
+ {
157
+ route: "POST /api/v1/orgs/:orgId/catalog/:itemId/install",
158
+ params: CatalogItemPathParams,
159
+ body: OrgPluginInstallBody,
160
+ },
161
+ {
162
+ route: "POST /api/v1/orgs/:orgId/catalog/:itemId/connectors",
163
+ params: CatalogItemPathParams,
164
+ body: OrgPluginConnectorsSchema,
165
+ },
166
+ {
167
+ route: "POST /api/v1/orgs/:orgId/connector-templates/:templateId/connectors",
168
+ params: ConnectorTemplatePathParams,
169
+ body: OrgTemplateConnectorSchema,
170
+ },
130
171
  {
131
172
  route: "PUT /api/v1/orgs/:orgId/catalog/:itemId/switch",
132
173
  params: CatalogItemPathParams,
@@ -553,6 +553,7 @@ export declare class PluginInstaller {
553
553
  */
554
554
  configureConnectors(orgId: string, actor: string, itemId: string, input: PluginInstallInput, opts?: {
555
555
  actorTokenId?: string;
556
+ auditDetail?: AuditDetail;
556
557
  }): Promise<{
557
558
  templateId: string;
558
559
  connectorId: string;
@@ -578,6 +579,7 @@ export declare class PluginInstaller {
578
579
  config: Omit<ConnectorInstallInput, "name">;
579
580
  }, opts?: {
580
581
  actorTokenId?: string;
582
+ auditDetail?: AuditDetail;
581
583
  }): Promise<{
582
584
  connector: ConnectorDetail;
583
585
  issues: ToolIssue[];
@@ -775,7 +775,7 @@ let PluginInstaller = class PluginInstaller {
775
775
  }
776
776
  if (actor === null)
777
777
  throw systemNeedsInput(manifest.name);
778
- const r = await this.connectors.create(orgId, actor, ci, opts.actorTokenId);
778
+ const r = await this.connectors.create(orgId, actor, ci, opts.actorTokenId, opts.auditDetail);
779
779
  await record({
780
780
  kind: "connector",
781
781
  ref: r.connector.id,
@@ -1692,7 +1692,7 @@ let PluginInstaller = class PluginInstaller {
1692
1692
  }));
1693
1693
  const out = [];
1694
1694
  for (const p of plans) {
1695
- const r = await this.connectors.create(orgId, actor, p.ci, opts.actorTokenId);
1695
+ const r = await this.connectors.create(orgId, actor, p.ci, opts.actorTokenId, opts.auditDetail);
1696
1696
  await this.recordConnector(missing.installId, r.connector.id, p.id);
1697
1697
  out.push({ templateId: p.id, connectorId: r.connector.id });
1698
1698
  }
@@ -1795,7 +1795,7 @@ let PluginInstaller = class PluginInstaller {
1795
1795
  }),
1796
1796
  };
1797
1797
  try {
1798
- const r = await this.connectors.create(orgId, actor, ci, opts.actorTokenId);
1798
+ const r = await this.connectors.create(orgId, actor, ci, opts.actorTokenId, opts.auditDetail);
1799
1799
  await this.recordOnLiveInstall(orgId, row.catalog_item_id, r.connector.id, ct.id);
1800
1800
  return r;
1801
1801
  }
@@ -38,4 +38,7 @@ export declare const ChannelGuideAckSchema: z.ZodObject<{
38
38
  export declare const ChannelPathParams: z.ZodObject<{
39
39
  connectionId: z.ZodString;
40
40
  }, z.core.$strip>;
41
+ export declare const ChannelSchemaParams: z.ZodObject<{
42
+ plugin: z.ZodString;
43
+ }, z.core.$strip>;
41
44
  export declare const CHANNEL_ROUTES: readonly RouteSchemas[];
@@ -28,8 +28,16 @@ export const ChannelGuideAckSchema = z
28
28
  .object({ hash: z.string().regex(/^[0-9a-f]{64}$/) })
29
29
  .strict();
30
30
  export const ChannelPathParams = z.object({ connectionId: z.string().min(1).max(100) });
31
+ export const ChannelSchemaParams = z.object({ plugin: z.string().min(1).max(214) });
31
32
  export const CHANNEL_ROUTES = [
32
33
  { route: "GET /api/v1/orgs/:orgId/channels" },
34
+ { route: "GET /api/v1/orgs/:orgId/channels/schema/:plugin", params: ChannelSchemaParams },
35
+ { route: "POST /api/v1/orgs/:orgId/channels", body: ChannelCreateSchema },
36
+ {
37
+ route: "POST /api/v1/orgs/:orgId/channels/:connectionId/guide-ack",
38
+ params: ChannelPathParams,
39
+ body: ChannelGuideAckSchema,
40
+ },
33
41
  { route: "GET /api/v1/orgs/:orgId/channels/:connectionId", params: ChannelPathParams },
34
42
  {
35
43
  route: "PATCH /api/v1/orgs/:orgId/channels/:connectionId",
@@ -196,9 +196,22 @@ export declare class ChannelConnections implements OnApplicationShutdown {
196
196
  list(orgId: string): Promise<ChannelConnectionView[]>;
197
197
  get(orgId: string, id: string): Promise<ChannelConnectionView>;
198
198
  /** 新建:插件须提供 channel@1 且在该组织启用;配置按 `connectionSchema` 校验;先 `verify`,失败不落库。 */
199
- create(orgId: string, input: CreateChannelInput, actorAccountId: string, actorTokenId?: string): Promise<ChannelConnectionView>;
199
+ create(orgId: string, input: CreateChannelInput, actorAccountId: string, actorTokenId?: string,
200
+ /** Merged into the audit detail (the Platform tool's `via: "agent"`). */
201
+ auditDetail?: Record<string, unknown>): Promise<ChannelConnectionView>;
200
202
  /** The rows of {@link create}, in their own transaction (the caller publishes after the commit). */
201
203
  private insertIn;
204
+ /**
205
+ * The read-only refusals of {@link create} that need no write (the Platform tool's precheck): the
206
+ * plugin provides a channel and is on in the org, the agent exists, and webhook inbound is
207
+ * available when asked for.
208
+ */
209
+ checkCreate(orgId: string, input: Pick<CreateChannelInput, "plugin" | "agentId" | "inboundMode">): Promise<void>;
210
+ /**
211
+ * The secret fields (dot paths) the inbound mode requires of the plugin's connection form
212
+ * (`x-ui.inboundModes`), for the Platform tool's person fields.
213
+ */
214
+ modeRequiredFields(plugin: string, mode: InboundMode): string[];
202
215
  /** The read-only refusals of {@link update} that need no write (the Platform tool's precheck). */
203
216
  checkUpdate(orgId: string, id: string, patch: UpdateChannelInput): Promise<void>;
204
217
  /**
@@ -223,7 +236,9 @@ export declare class ChannelConnections implements OnApplicationShutdown {
223
236
  ackGuide(org: {
224
237
  orgId: string;
225
238
  role: OrgRole;
226
- }, id: string, hash: string, actorAccountId: string, actorTokenId?: string): Promise<ChannelConnectionView>;
239
+ }, id: string, hash: string, actorAccountId: string, actorTokenId?: string,
240
+ /** Merged into the audit detail (the Platform tool's `via: "agent"`). */
241
+ auditDetail?: Record<string, unknown>): Promise<ChannelConnectionView>;
227
242
  /** The row of {@link ackGuide}, in its own transaction. */
228
243
  private ackIn;
229
244
  /** 删除(软删除,同一事务删掉密钥);持有长连接的副本收到广播后断开。 */
@@ -385,7 +385,9 @@ let ChannelConnections = class ChannelConnections {
385
385
  return this.viewOf(row);
386
386
  }
387
387
  /** 新建:插件须提供 channel@1 且在该组织启用;配置按 `connectionSchema` 校验;先 `verify`,失败不落库。 */
388
- async create(orgId, input, actorAccountId, actorTokenId) {
388
+ async create(orgId, input, actorAccountId, actorTokenId,
389
+ /** Merged into the audit detail (the Platform tool's `via: "agent"`). */
390
+ auditDetail) {
389
391
  const channel = this.channel(input.plugin);
390
392
  await this.assertEnabled(orgId, input.plugin);
391
393
  const schema = channel.connectionSchema;
@@ -410,6 +412,7 @@ let ChannelConnections = class ChannelConnections {
410
412
  guideAck,
411
413
  actorAccountId,
412
414
  actorTokenId,
415
+ auditDetail,
413
416
  });
414
417
  this.reportSecrets(schema, full);
415
418
  await this.changed(id, false);
@@ -451,10 +454,30 @@ let ChannelConnections = class ChannelConnections {
451
454
  plugin: input.plugin,
452
455
  agentId: input.agentId,
453
456
  inboundMode: input.inboundMode ?? "long_connection",
457
+ ...a.auditDetail,
454
458
  },
455
459
  });
456
460
  return inserted;
457
461
  }
462
+ /**
463
+ * The read-only refusals of {@link create} that need no write (the Platform tool's precheck): the
464
+ * plugin provides a channel and is on in the org, the agent exists, and webhook inbound is
465
+ * available when asked for.
466
+ */
467
+ async checkCreate(orgId, input) {
468
+ this.channel(input.plugin);
469
+ await this.assertEnabled(orgId, input.plugin);
470
+ if (input.inboundMode === "webhook")
471
+ this.assertWebhookAvailable(input.plugin);
472
+ await this.assertAgent(orgId, input.agentId);
473
+ }
474
+ /**
475
+ * The secret fields (dot paths) the inbound mode requires of the plugin's connection form
476
+ * (`x-ui.inboundModes`), for the Platform tool's person fields.
477
+ */
478
+ modeRequiredFields(plugin, mode) {
479
+ return missingInboundModeFields(this.jsonSchema(plugin), mode, () => false);
480
+ }
458
481
  /** The read-only refusals of {@link update} that need no write (the Platform tool's precheck). */
459
482
  async checkUpdate(orgId, id, patch) {
460
483
  const current = await this.live(orgId).where("id", "=", id).executeTakeFirst();
@@ -617,7 +640,9 @@ let ChannelConnections = class ChannelConnections {
617
640
  * first). A plugin without a guide, or whose item the org's catalog does not show -> 404
618
641
  * `catalog.guide_not_found`.
619
642
  */
620
- async ackGuide(org, id, hash, actorAccountId, actorTokenId) {
643
+ async ackGuide(org, id, hash, actorAccountId, actorTokenId,
644
+ /** Merged into the audit detail (the Platform tool's `via: "agent"`). */
645
+ auditDetail) {
621
646
  const { orgId } = org;
622
647
  const current = await this.live(orgId).where("id", "=", id).executeTakeFirst();
623
648
  if (!current)
@@ -633,11 +658,11 @@ let ChannelConnections = class ChannelConnections {
633
658
  if (ack.hash !== hash) {
634
659
  throw new ApiError("channel.guide_changed", "The plugin's setup guide changed since it was shown; review the new guide first");
635
660
  }
636
- const row = await this.ackIn(orgId, id, ack, actorAccountId, actorTokenId);
661
+ const row = await this.ackIn(orgId, id, ack, actorAccountId, actorTokenId, auditDetail);
637
662
  return this.viewOf(row);
638
663
  }
639
664
  /** The row of {@link ackGuide}, in its own transaction. */
640
- async ackIn(orgId, id, ack, actorAccountId, actorTokenId) {
665
+ async ackIn(orgId, id, ack, actorAccountId, actorTokenId, auditDetail) {
641
666
  await this.orgLock.lockAndAuthorize(orgId, actorAccountId, "channels.manage");
642
667
  const row = await this.db
643
668
  .updateTable("channel_connections")
@@ -655,7 +680,7 @@ let ChannelConnections = class ChannelConnections {
655
680
  orgId,
656
681
  action: "channel.guide_confirmed",
657
682
  target: id,
658
- detail: { guideId: ack.guideId, version: ack.version },
683
+ detail: { guideId: ack.guideId, version: ack.version, ...auditDetail },
659
684
  });
660
685
  return row;
661
686
  }
@@ -962,6 +962,23 @@ class Delivery {
962
962
  }), this.key(e.seq));
963
963
  return this.advance(e.seq);
964
964
  }
965
+ case "tool_result": {
966
+ // a Platform operation's link card (platform web parity spec §6): a link to the web page
967
+ // where the person decides; an OAuth connect opens the conversation, whose card starts it
968
+ const v = e.payload.view;
969
+ if (v?.kind !== "handoff")
970
+ return;
971
+ await this.send(this.base === undefined
972
+ ? { text: phrase("handleOnWeb", this.locale) }
973
+ : cardMessage(v.title[this.locale], {
974
+ kind: "bind",
975
+ text: v.title[this.locale],
976
+ url: v.target.type === "link"
977
+ ? `${this.base}${v.target.url}`
978
+ : conversationUrl(this.base, this.conversationId),
979
+ }), this.key(e.seq));
980
+ return this.advance(e.seq);
981
+ }
965
982
  case "approval_decided": {
966
983
  const at = await this.cardMessageOf("approval", e.payload.approvalId);
967
984
  if (!at || this.base === undefined)
@@ -501,6 +501,10 @@ export type LogContentBlock = Exclude<ContentBlock, MediaBlock> | (MediaBlock ex
501
501
  kind: "ref";
502
502
  }>;
503
503
  } : never : never);
504
+ /** The longest handoff card title (`ToolViewSchema` kind `handoff`), per language. */
505
+ export declare const HANDOFF_TITLE_MAX_CHARS = 200;
506
+ /** The longest handoff link (a relative web path). */
507
+ export declare const HANDOFF_URL_MAX_CHARS = 2000;
504
508
  /**
505
509
  * Structured view of a builtin tool's result (UI refresh B, spec §5.5 / §5.9): display only, like
506
510
  * `display`. `command`: `Bash` (the model's `description`, the exit code, null when the
@@ -513,6 +517,10 @@ export type LogContentBlock = Exclude<ContentBlock, MediaBlock> | (MediaBlock ex
513
517
  * `not_loaded`: a call to a tool the catalog holds but the step's request did not carry
514
518
  * (ToolSearch mode, spec 5.5): expected behaviour, the model is told to load it first. The result
515
519
  * stays `isError: true` for the model; the web shows it as a neutral outcome too.
520
+ * `handoff`: a `Platform` operation whose decision stays with a person on a web page (platform web
521
+ * parity spec §4.4, §6): the card's title and either a relative web path (`link`, also in the
522
+ * result text as `reviewUrl`) or a connector to connect (`connect`: the web's Connect button starts
523
+ * the OAuth flow from the person's session). IM forwards it as a `bind` card.
516
524
  */
517
525
  export declare const ToolViewSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
518
526
  kind: z.ZodLiteral<"command">;
@@ -561,6 +569,19 @@ export declare const ToolViewSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
561
569
  }>;
562
570
  }, z.core.$strip>, z.ZodObject<{
563
571
  kind: z.ZodLiteral<"not_loaded">;
572
+ }, z.core.$strip>, z.ZodObject<{
573
+ kind: z.ZodLiteral<"handoff">;
574
+ title: z.ZodObject<{
575
+ zh: z.ZodString;
576
+ en: z.ZodString;
577
+ }, z.core.$strip>;
578
+ target: z.ZodDiscriminatedUnion<[z.ZodObject<{
579
+ type: z.ZodLiteral<"link">;
580
+ url: z.ZodString;
581
+ }, z.core.$strip>, z.ZodObject<{
582
+ type: z.ZodLiteral<"connect">;
583
+ connectorId: z.ZodString;
584
+ }, z.core.$strip>], "type">;
564
585
  }, z.core.$strip>], "kind">;
565
586
  export type ToolView = z.infer<typeof ToolViewSchema>;
566
587
  /**
@@ -1424,6 +1445,19 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
1424
1445
  }>;
1425
1446
  }, z.core.$strip>, z.ZodObject<{
1426
1447
  kind: z.ZodLiteral<"not_loaded">;
1448
+ }, z.core.$strip>, z.ZodObject<{
1449
+ kind: z.ZodLiteral<"handoff">;
1450
+ title: z.ZodObject<{
1451
+ zh: z.ZodString;
1452
+ en: z.ZodString;
1453
+ }, z.core.$strip>;
1454
+ target: z.ZodDiscriminatedUnion<[z.ZodObject<{
1455
+ type: z.ZodLiteral<"link">;
1456
+ url: z.ZodString;
1457
+ }, z.core.$strip>, z.ZodObject<{
1458
+ type: z.ZodLiteral<"connect">;
1459
+ connectorId: z.ZodString;
1460
+ }, z.core.$strip>], "type">;
1427
1461
  }, z.core.$strip>], "kind">>;
1428
1462
  card: z.ZodOptional<z.ZodObject<{
1429
1463
  plugin: z.ZodString;
@@ -516,6 +516,12 @@ const FileStateViewSchema = z.object({
516
516
  size: count,
517
517
  sha256: z.string().regex(/^[0-9a-f]{64}$/),
518
518
  });
519
+ /** The longest handoff card title (`ToolViewSchema` kind `handoff`), per language. */
520
+ export const HANDOFF_TITLE_MAX_CHARS = 200;
521
+ /** The longest handoff link (a relative web path). */
522
+ export const HANDOFF_URL_MAX_CHARS = 2000;
523
+ /** A relative web path: one leading `/`, never `//` (another host) or a backslash. */
524
+ const HANDOFF_PATH = /^\/(?![/\\])[^\\\s]*$/;
519
525
  /**
520
526
  * Structured view of a builtin tool's result (UI refresh B, spec §5.5 / §5.9): display only, like
521
527
  * `display`. `command`: `Bash` (the model's `description`, the exit code, null when the
@@ -528,6 +534,10 @@ const FileStateViewSchema = z.object({
528
534
  * `not_loaded`: a call to a tool the catalog holds but the step's request did not carry
529
535
  * (ToolSearch mode, spec 5.5): expected behaviour, the model is told to load it first. The result
530
536
  * stays `isError: true` for the model; the web shows it as a neutral outcome too.
537
+ * `handoff`: a `Platform` operation whose decision stays with a person on a web page (platform web
538
+ * parity spec §4.4, §6): the card's title and either a relative web path (`link`, also in the
539
+ * result text as `reviewUrl`) or a connector to connect (`connect`: the web's Connect button starts
540
+ * the OAuth flow from the person's session). IM forwards it as a `bind` card.
531
541
  */
532
542
  export const ToolViewSchema = z.discriminatedUnion("kind", [
533
543
  z.object({
@@ -569,6 +579,20 @@ export const ToolViewSchema = z.discriminatedUnion("kind", [
569
579
  reason: z.enum(["not_read", "modified"]),
570
580
  }),
571
581
  z.object({ kind: z.literal("not_loaded") }),
582
+ z.object({
583
+ kind: z.literal("handoff"),
584
+ title: z.object({
585
+ zh: z.string().min(1).max(HANDOFF_TITLE_MAX_CHARS),
586
+ en: z.string().min(1).max(HANDOFF_TITLE_MAX_CHARS),
587
+ }),
588
+ target: z.discriminatedUnion("type", [
589
+ z.object({
590
+ type: z.literal("link"),
591
+ url: z.string().max(HANDOFF_URL_MAX_CHARS).regex(HANDOFF_PATH, "a relative web path"),
592
+ }),
593
+ z.object({ type: z.literal("connect"), connectorId: z.string().min(1).max(100) }),
594
+ ]),
595
+ }),
572
596
  ]);
573
597
  const ModelUsageShape = {
574
598
  inputTokens: count,
@@ -48,6 +48,8 @@ export interface RewrapResult {
48
48
  dataKeys: number;
49
49
  /** Unexpired one-time initial passwords (`account_initial_passwords`) now sealed with it. */
50
50
  initialPasswords: number;
51
+ /** Unexpired sealed Platform reveals (`platform_sealed_reveals`, invitation links) now sealed with it. */
52
+ sealedReveals: number;
51
53
  }
52
54
  /** Rows rewrapped per transaction by default. */
53
55
  export declare const REWRAP_BATCH_SIZE = 500;
@@ -58,13 +60,18 @@ export declare const initialPasswordAad: (accountId: string) => string;
58
60
  * by ","): a row moved to another approval, or whose paths are altered, fails to unwrap.
59
61
  */
60
62
  export declare const platformSealedInputAad: (approvalId: string, paths: readonly string[]) => string;
63
+ /**
64
+ * The AAD binding a sealed Platform reveal (an invitation link) to its subject: a row moved to
65
+ * another subject fails to unwrap.
66
+ */
67
+ export declare const platformSealedRevealAad: (id: string) => string;
61
68
  type RewrapHandles = {
62
69
  db: Pick<KernelDb, "db">;
63
70
  txHost: Pick<TransactionHost, "run">;
64
71
  };
65
72
  /**
66
73
  * Rewraps everything sealed with a master key other than the keyring's current one (org data keys
67
- * and unexpired initial passwords) with the current key, `batchSize` rows per transaction, until
74
+ * and unexpired initial passwords and sealed reveals) with the current key, `batchSize` rows per transaction, until
68
75
  * none is left. Checks first that the keyring holds every master key in use and throws (naming row
69
76
  * ids and key ids, never key material) before writing anything when it does not. Idempotent: a
70
77
  * second run finds nothing; concurrent runs lock the same rows and skip the ones already done.
@@ -152,6 +152,11 @@ export const initialPasswordAad = (accountId) => `capybara:initial-password:${ac
152
152
  * by ","): a row moved to another approval, or whose paths are altered, fails to unwrap.
153
153
  */
154
154
  export const platformSealedInputAad = (approvalId, paths) => `capybara:platform-sealed-input:${approvalId}:${[...paths].sort().join(",")}`;
155
+ /**
156
+ * The AAD binding a sealed Platform reveal (an invitation link) to its subject: a row moved to
157
+ * another subject fails to unwrap.
158
+ */
159
+ export const platformSealedRevealAad = (id) => `capybara:platform-sealed-reveal:${id}`;
155
160
  const MASTER_KEYED = [
156
161
  {
157
162
  table: "org_data_keys",
@@ -167,6 +172,13 @@ const MASTER_KEYED = [
167
172
  aad: initialPasswordAad,
168
173
  hasExpiresAt: true,
169
174
  },
175
+ {
176
+ table: "platform_sealed_reveals",
177
+ idColumn: "id",
178
+ dataColumn: "ciphertext",
179
+ aad: platformSealedRevealAad,
180
+ hasExpiresAt: true,
181
+ },
170
182
  ];
171
183
  function staleRows(db, t, keyring) {
172
184
  let q = db
@@ -186,7 +198,7 @@ function assertKnown(t, keyring, rows) {
186
198
  }
187
199
  /**
188
200
  * Rewraps everything sealed with a master key other than the keyring's current one (org data keys
189
- * and unexpired initial passwords) with the current key, `batchSize` rows per transaction, until
201
+ * and unexpired initial passwords and sealed reveals) with the current key, `batchSize` rows per transaction, until
190
202
  * none is left. Checks first that the keyring holds every master key in use and throws (naming row
191
203
  * ids and key ids, never key material) before writing anything when it does not. Idempotent: a
192
204
  * second run finds nothing; concurrent runs lock the same rows and skip the ones already done.
@@ -247,5 +259,6 @@ export async function rewrapToCurrentMasterKey(handles, keyring, opts = {}) {
247
259
  return {
248
260
  dataKeys: counts.get("org_data_keys") ?? 0,
249
261
  initialPasswords: counts.get("account_initial_passwords") ?? 0,
262
+ sealedReveals: counts.get("platform_sealed_reveals") ?? 0,
250
263
  };
251
264
  }
@@ -128,6 +128,24 @@ export interface PlatformSealedInputsTable {
128
128
  expires_at: Date | string;
129
129
  created_at: Ts;
130
130
  }
131
+ /**
132
+ * A value a Platform call made for the person who approved it, read once on the web (migration
133
+ * 0170; first kind: an invitation link).
134
+ */
135
+ export interface PlatformSealedRevealsTable {
136
+ /** The subject the value belongs to (the invitation id); part of the AAD. */
137
+ id: string;
138
+ kind: "invitation_link";
139
+ org_id: string;
140
+ recipient_account_id: string;
141
+ conversation_id: string;
142
+ run_id: string;
143
+ call_id: string;
144
+ master_key_id: string;
145
+ ciphertext: Buffer;
146
+ expires_at: Date | string;
147
+ created_at: Ts;
148
+ }
131
149
  export interface IdentitiesTable {
132
150
  source: string;
133
151
  external_id: string;
@@ -1625,6 +1643,7 @@ export interface KernelDatabase {
1625
1643
  org_data_keys: OrgDataKeysTable;
1626
1644
  account_initial_passwords: AccountInitialPasswordsTable;
1627
1645
  platform_sealed_inputs: PlatformSealedInputsTable;
1646
+ platform_sealed_reveals: PlatformSealedRevealsTable;
1628
1647
  identities: IdentitiesTable;
1629
1648
  local_passwords: LocalPasswordsTable;
1630
1649
  orgs: OrgsTable;
@@ -1,9 +1,8 @@
1
1
  import type { SandboxMode } from "../sandbox/modes.js";
2
2
  /**
3
3
  * What decides a conversation's working root (project root spec §4.3): the latest `project_root`
4
- * event of its root conversation (sub-agents inherit their root's binding). Null: the conversation
5
- * is free, or no run of it has recorded a snapshot yet (a bound conversation before its first run
6
- * start, an older log).
4
+ * event of its root conversation (sub-agents inherit their root's binding), or the bound root
5
+ * itself while no run has recorded one yet. Null: the conversation is free.
7
6
  */
8
7
  export interface WorkingProject {
9
8
  /** The project's root on the device, as the event recorded it. */
package/dist/errors.d.ts CHANGED
@@ -93,9 +93,19 @@ export declare const ERROR_CODES: {
93
93
  readonly "member.not_found": 404;
94
94
  readonly "member.already_exists": 409;
95
95
  readonly "member.anonymous_guest": 409;
96
+ /** A Platform member operation aimed at the actor's own membership (spec §7.2: never offered). */
97
+ readonly "member.self": 403;
98
+ /** A Platform member operation touching an owner or granting owner (spec §7.2). */
99
+ readonly "member.owner_untouchable": 403;
100
+ /** A Platform member operation raising someone above the actor's own role (spec §7.2). */
101
+ readonly "member.role_above_actor": 403;
96
102
  readonly "invitation.invalid": 404;
97
103
  readonly "invitation.expired": 410;
98
104
  readonly "invitation.used": 409;
105
+ /** `orgs.invite` outside an approved Platform call: its link could never be shown. */
106
+ readonly "invitation.create_needs_approval": 409;
107
+ /** No invitation link to show: read already, expired, or not a call the reader approved. */
108
+ readonly "invitation.link_unavailable": 404;
99
109
  readonly "extension.not_found": 404;
100
110
  /** The extension registers no tool of that name (org tool switches, layering spec A §7). */
101
111
  readonly "extension.tool_not_found": 404;