@capybara-hq/kernel 0.1.0-rc.57 → 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 (126) hide show
  1. package/dist/admin/extensions.controller.d.ts +2 -10
  2. package/dist/admin/extensions.controller.js +2 -24
  3. package/dist/admin/extensions.schemas.d.ts +21 -0
  4. package/dist/admin/extensions.schemas.js +37 -0
  5. package/dist/catalog/marketplaces.service.d.ts +1 -1
  6. package/dist/catalog/org-catalog.controller.d.ts +0 -5
  7. package/dist/catalog/org-catalog.controller.js +3 -17
  8. package/dist/catalog/org-catalog.schemas.d.ts +43 -0
  9. package/dist/catalog/org-catalog.schemas.js +43 -2
  10. package/dist/catalog/org-extension-switch.d.ts +3 -1
  11. package/dist/catalog/org-extension-switch.js +12 -5
  12. package/dist/catalog/org-extension.controller.d.ts +2 -21
  13. package/dist/catalog/org-extension.controller.js +1 -38
  14. package/dist/catalog/org-extension.schemas.d.ts +31 -0
  15. package/dist/catalog/org-extension.schemas.js +65 -0
  16. package/dist/catalog/plugin-install.d.ts +2 -0
  17. package/dist/catalog/plugin-install.js +3 -3
  18. package/dist/channels/actions.js +2 -0
  19. package/dist/channels/cards.d.ts +8 -0
  20. package/dist/channels/cards.js +18 -0
  21. package/dist/channels/channels.schemas.d.ts +3 -0
  22. package/dist/channels/channels.schemas.js +8 -0
  23. package/dist/channels/connections.service.d.ts +17 -2
  24. package/dist/channels/connections.service.js +30 -5
  25. package/dist/channels/outbound.js +25 -1
  26. package/dist/channels/phrases.d.ts +10 -0
  27. package/dist/channels/phrases.js +10 -0
  28. package/dist/conversations/conversations.module.js +4 -0
  29. package/dist/conversations/events.d.ts +35 -0
  30. package/dist/conversations/events.js +29 -0
  31. package/dist/conversations/leak-check.d.ts +26 -0
  32. package/dist/conversations/leak-check.js +69 -0
  33. package/dist/ctx/secrets.d.ts +13 -1
  34. package/dist/ctx/secrets.js +19 -1
  35. package/dist/db/kernel-schema.d.ts +34 -0
  36. package/dist/devices/working-root.d.ts +2 -3
  37. package/dist/errors.d.ts +19 -0
  38. package/dist/errors.js +19 -0
  39. package/dist/extensions/deployment-config.d.ts +6 -2
  40. package/dist/extensions/deployment-config.js +35 -23
  41. package/dist/extensions/org-config.d.ts +2 -0
  42. package/dist/extensions/org-config.js +1 -0
  43. package/dist/extensions/org-overrides.d.ts +2 -0
  44. package/dist/extensions/org-overrides.js +3 -2
  45. package/dist/http/api.module.js +6 -0
  46. package/dist/identity/initial-passwords.job.d.ts +3 -2
  47. package/dist/identity/initial-passwords.job.js +11 -5
  48. package/dist/orgs/invitations.controller.d.ts +3 -11
  49. package/dist/orgs/invitations.controller.js +9 -10
  50. package/dist/orgs/invitations.service.d.ts +12 -2
  51. package/dist/orgs/invitations.service.js +14 -7
  52. package/dist/orgs/members.service.d.ts +12 -2
  53. package/dist/orgs/members.service.js +10 -8
  54. package/dist/orgs/orgs.controller.d.ts +4 -12
  55. package/dist/orgs/orgs.controller.js +10 -10
  56. package/dist/orgs/orgs.schemas.d.ts +26 -0
  57. package/dist/orgs/orgs.schemas.js +22 -0
  58. package/dist/platform/connector-person-fields.d.ts +67 -0
  59. package/dist/platform/connector-person-fields.js +129 -0
  60. package/dist/platform/exclusions.js +6 -141
  61. package/dist/platform/method.js +1 -0
  62. package/dist/platform/operation.d.ts +61 -2
  63. package/dist/platform/operation.js +4 -4
  64. package/dist/platform/ops/accounts.ops.js +1 -0
  65. package/dist/platform/ops/channels.ops.d.ts +10 -3
  66. package/dist/platform/ops/channels.ops.js +223 -5
  67. package/dist/platform/ops/connectors.ops.d.ts +22 -4
  68. package/dist/platform/ops/connectors.ops.js +664 -13
  69. package/dist/platform/ops/extensions-admin.ops.d.ts +15 -2
  70. package/dist/platform/ops/extensions-admin.ops.js +153 -5
  71. package/dist/platform/ops/extensions.ops.d.ts +19 -5
  72. package/dist/platform/ops/extensions.ops.js +285 -10
  73. package/dist/platform/ops/org-plugins.ops.d.ts +15 -2
  74. package/dist/platform/ops/org-plugins.ops.js +323 -4
  75. package/dist/platform/ops/orgs.ops.d.ts +40 -3
  76. package/dist/platform/ops/orgs.ops.js +293 -12
  77. package/dist/platform/ops/person-inputs.d.ts +65 -0
  78. package/dist/platform/ops/person-inputs.js +129 -0
  79. package/dist/platform/ops/plugins.ops.d.ts +3 -1
  80. package/dist/platform/ops/plugins.ops.js +33 -20
  81. package/dist/platform/parity.d.ts +7 -2
  82. package/dist/platform/parity.js +75 -13
  83. package/dist/platform/person-fields.d.ts +119 -0
  84. package/dist/platform/person-fields.js +403 -0
  85. package/dist/platform/platform.module.d.ts +4 -3
  86. package/dist/platform/platform.module.js +8 -5
  87. package/dist/platform/route-schemas.js +2 -0
  88. package/dist/platform/sealed-inputs.d.ts +44 -0
  89. package/dist/platform/sealed-inputs.js +116 -0
  90. package/dist/platform/sealed-reveals.controller.d.ts +20 -0
  91. package/dist/platform/sealed-reveals.controller.js +48 -0
  92. package/dist/platform/sealed-reveals.d.ts +52 -0
  93. package/dist/platform/sealed-reveals.js +153 -0
  94. package/dist/runtime/project/knowledge.js +24 -19
  95. package/dist/runtime/waits.js +8 -2
  96. package/dist/sandbox/permission-facts.d.ts +5 -1
  97. package/dist/sandbox/permission-facts.js +8 -2
  98. package/dist/setup/setup-guides.service.d.ts +5 -0
  99. package/dist/setup/setup-guides.service.js +2 -1
  100. package/dist/tools/approvals.controller.d.ts +1 -0
  101. package/dist/tools/approvals.controller.js +19 -0
  102. package/dist/tools/approvals.service.d.ts +50 -1
  103. package/dist/tools/approvals.service.js +118 -10
  104. package/dist/tools/builtins/builtin-tools.d.ts +3 -0
  105. package/dist/tools/builtins/builtin-tools.js +31 -9
  106. package/dist/tools/builtins/platform.d.ts +20 -0
  107. package/dist/tools/builtins/platform.js +214 -15
  108. package/dist/tools/connectors.controller.d.ts +6 -7
  109. package/dist/tools/connectors.controller.js +4 -44
  110. package/dist/tools/connectors.schemas.d.ts +170 -1
  111. package/dist/tools/connectors.schemas.js +82 -3
  112. package/dist/tools/connectors.service.d.ts +16 -6
  113. package/dist/tools/connectors.service.js +39 -24
  114. package/dist/tools/oauth/oauth.controller.d.ts +3 -6
  115. package/dist/tools/oauth/oauth.controller.js +3 -12
  116. package/dist/tools/oauth/oauth.schemas.d.ts +14 -0
  117. package/dist/tools/oauth/oauth.schemas.js +27 -0
  118. package/dist/tools/pipeline.d.ts +31 -2
  119. package/dist/tools/pipeline.js +89 -17
  120. package/dist/tools/policy.d.ts +4 -0
  121. package/dist/tools/policy.js +8 -0
  122. package/dist/tools/registry.d.ts +29 -0
  123. package/dist/tools/tools.module.js +3 -0
  124. package/package.json +3 -3
  125. package/src/migrations/0169_platform_sealed_inputs.sql +23 -0
  126. package/src/migrations/0170_platform_sealed_reveals.sql +27 -0
@@ -111,12 +111,13 @@ let MembersService = class MembersService {
111
111
  * 发起人的角色在组织行锁内实时重读(spec 3.6 R5):已不是成员或低于 admin → `forbidden`。
112
112
  * 目标是匿名访客 → `member.anonymous_guest`。
113
113
  */
114
- async changeRole(orgId, targetId, role, actorAccountId, actorTokenId) {
115
- await this.changeRoleIn(orgId, targetId, role, actorAccountId, actorTokenId);
114
+ async changeRole(orgId, targetId, role, actorAccountId, actorTokenId, opts = {}) {
115
+ await this.changeRoleIn(orgId, targetId, role, actorAccountId, actorTokenId, opts);
116
116
  }
117
- async changeRoleIn(orgId, targetId, role, actorAccountId, actorTokenId) {
117
+ async changeRoleIn(orgId, targetId, role, actorAccountId, actorTokenId, opts) {
118
118
  const { role: actorRole } = await this.orgLock.lockAndAuthorize(orgId, actorAccountId, "org.members.manage");
119
119
  const before = await this.requireMember(orgId, targetId);
120
+ opts.guard?.(actorRole, before);
120
121
  await rejectAnonymousGuest(this.db.db, targetId);
121
122
  if ((role === "owner" || before === "owner") && actorRole !== "owner") {
122
123
  throw new ApiError("org.owner_required", "Only an owner can change owner roles");
@@ -131,7 +132,7 @@ let MembersService = class MembersService {
131
132
  orgId,
132
133
  action: "org.member.role_changed",
133
134
  target: targetId,
134
- detail: { from: before, to: role },
135
+ detail: { from: before, to: role, ...opts.auditDetail },
135
136
  });
136
137
  }
137
138
  /**
@@ -139,16 +140,17 @@ let MembersService = class MembersService {
139
140
  * 走离职处理({@link Offboarding.offboard},原因 `removed`),与之同一事务;提交后写吊销标记、发布事件。
140
141
  * 匿名访客不能移出(`member.anonymous_guest`;不再需要匿名访问时把渠道连接改回绑定策略)。
141
142
  */
142
- async remove(orgId, targetId, actorAccountId, actorTokenId) {
143
- await this.removeIn(orgId, targetId, actorAccountId, actorTokenId);
143
+ async remove(orgId, targetId, actorAccountId, actorTokenId, opts = {}) {
144
+ await this.removeIn(orgId, targetId, actorAccountId, actorTokenId, opts);
144
145
  }
145
- async removeIn(orgId, targetId, actorAccountId, actorTokenId) {
146
+ async removeIn(orgId, targetId, actorAccountId, actorTokenId, opts) {
146
147
  // an unauthorized call is refused before it holds off the org's run writes
147
148
  await this.orgLock.precheck(orgId, actorAccountId, "org.members.manage");
148
149
  // offboarding: the org admission lock first (`Offboarding.offboard`)
149
150
  await this.orgLock.lockForRemoval(orgId);
150
151
  const { role: actorRole } = await this.orgLock.lockAndAuthorize(orgId, actorAccountId, "org.members.manage");
151
152
  const before = await this.requireMember(orgId, targetId);
153
+ opts.guard?.(actorRole, before);
152
154
  await rejectAnonymousGuest(this.db.db, targetId);
153
155
  if (before === "owner" && actorRole !== "owner") {
154
156
  throw new ApiError("org.owner_required", "Only an owner can remove an owner");
@@ -162,7 +164,7 @@ let MembersService = class MembersService {
162
164
  orgId,
163
165
  action: "org.member.removed",
164
166
  target: targetId,
165
- detail: { role: before },
167
+ detail: { role: before, ...opts.auditDetail },
166
168
  });
167
169
  return res;
168
170
  }
@@ -4,9 +4,9 @@ import { type Principal } from "../identity/principal.js";
4
4
  import { type Member, MembersService } from "./members.service.js";
5
5
  import { OrgNetworkAllowances } from "./network-allowances.service.js";
6
6
  import { type OrgContext } from "./org.guard.js";
7
- import { type NetworkAllowanceView, OrgUpdateBody } from "./orgs.schemas.js";
7
+ import { MemberParams, MemberRoleBody, type NetworkAllowanceView, OrgUpdateBody } from "./orgs.schemas.js";
8
8
  import { type Org, OrgsService } from "./orgs.service.js";
9
- import { type OrgRole } from "./roles.js";
9
+ import type { OrgRole } from "./roles.js";
10
10
  declare const CreateSchema: z.ZodObject<{
11
11
  name: z.ZodString;
12
12
  slug: z.ZodOptional<z.ZodString>;
@@ -23,14 +23,6 @@ declare const ServiceTokenSchema: z.ZodObject<{
23
23
  }>;
24
24
  expiresAt: z.ZodOptional<z.ZodPipe<z.ZodISODateTime, z.ZodTransform<Date, string>>>;
25
25
  }, z.core.$strip>;
26
- declare const RoleSchema: z.ZodObject<{
27
- role: z.ZodEnum<{
28
- admin: "admin";
29
- guest: "guest";
30
- member: "member";
31
- owner: "owner";
32
- }>;
33
- }, z.core.$strip>;
34
26
  /** 组织与成员(`/api/v1/orgs`)。组织级路由由 `@OrgAction` + OrgGuard 每请求实时鉴权。 */
35
27
  export declare class OrgsController {
36
28
  private readonly orgs;
@@ -67,11 +59,11 @@ export declare class OrgsController {
67
59
  listNetworkAllowances(org: OrgContext): Promise<{
68
60
  allowances: NetworkAllowanceView[];
69
61
  }>;
70
- changeRole(principal: Principal, org: OrgContext, accountId: string, body: z.infer<typeof RoleSchema>): Promise<{
62
+ changeRole(principal: Principal, org: OrgContext, { accountId }: z.infer<typeof MemberParams>, body: z.infer<typeof MemberRoleBody>): Promise<{
71
63
  accountId: string;
72
64
  role: OrgRole;
73
65
  }>;
74
- removeMember(principal: Principal, org: OrgContext, accountId: string): Promise<void>;
66
+ removeMember(principal: Principal, org: OrgContext, { accountId }: z.infer<typeof MemberParams>): Promise<void>;
75
67
  createServiceToken(principal: Principal, org: OrgContext, body: z.infer<typeof ServiceTokenSchema>): Promise<{
76
68
  token: string;
77
69
  record: ApiTokenRecord;
@@ -13,13 +13,12 @@ import { ApiError } from "../errors.js";
13
13
  import { ApiTokenService, FutureIsoDate } from "../identity/api-tokens.js";
14
14
  import { CurrentPrincipal, patTokenId, requireUser, SessionOnly, } from "../identity/principal.js";
15
15
  import { createZodDto } from "../infra/validation/create-zod-dto.js";
16
- import { ZBody } from "../infra/validation/zod-params.js";
16
+ import { ZBody, ZParam } from "../infra/validation/zod-params.js";
17
17
  import { MembersService } from "./members.service.js";
18
18
  import { OrgNetworkAllowances } from "./network-allowances.service.js";
19
19
  import { CurrentOrg, OrgAction } from "./org.guard.js";
20
- import { networkAllowanceView, OrgUpdateBody } from "./orgs.schemas.js";
20
+ import { MemberParams, MemberRoleBody, networkAllowanceView, OrgUpdateBody, } from "./orgs.schemas.js";
21
21
  import { OrgsService } from "./orgs.service.js";
22
- import { ORG_ROLES } from "./roles.js";
23
22
  const CreateSchema = z.object({
24
23
  name: z.string().min(1).max(100),
25
24
  slug: z.string().min(1).max(40).optional(),
@@ -38,8 +37,9 @@ const ServiceTokenSchema = z.object({
38
37
  });
39
38
  class ServiceTokenBody extends createZodDto(ServiceTokenSchema, "ServiceTokenBody") {
40
39
  }
41
- const RoleSchema = z.object({ role: z.enum(ORG_ROLES) });
42
- class MemberRoleBody extends createZodDto(RoleSchema, "MemberRoleBody") {
40
+ class MemberRoleBodyDto extends createZodDto(MemberRoleBody, "MemberRoleBody") {
41
+ }
42
+ class MemberParamsDto extends createZodDto(MemberParams, "MemberParams") {
43
43
  }
44
44
  /** 组织与成员(`/api/v1/orgs`)。组织级路由由 `@OrgAction` + OrgGuard 每请求实时鉴权。 */
45
45
  let OrgsController = class OrgsController {
@@ -94,12 +94,12 @@ let OrgsController = class OrgsController {
94
94
  async listNetworkAllowances(org) {
95
95
  return { allowances: (await this.allowances.list(org.orgId)).map(networkAllowanceView) };
96
96
  }
97
- async changeRole(principal, org, accountId, body) {
97
+ async changeRole(principal, org, { accountId }, body) {
98
98
  const p = requireUser(principal);
99
99
  await this.members.changeRole(org.orgId, accountId, body.role, p.account.id, patTokenId(p));
100
100
  return { accountId, role: body.role };
101
101
  }
102
- async removeMember(principal, org, accountId) {
102
+ async removeMember(principal, org, { accountId }) {
103
103
  const p = requireUser(principal);
104
104
  await this.members.remove(org.orgId, accountId, p.account.id, patTokenId(p));
105
105
  }
@@ -173,8 +173,8 @@ __decorate([
173
173
  OrgAction("org.members.manage"),
174
174
  __param(0, CurrentPrincipal()),
175
175
  __param(1, CurrentOrg()),
176
- __param(2, Param("accountId")),
177
- __param(3, ZBody(MemberRoleBody))
176
+ __param(2, ZParam(MemberParamsDto)),
177
+ __param(3, ZBody(MemberRoleBodyDto))
178
178
  ], OrgsController.prototype, "changeRole", null);
179
179
  __decorate([
180
180
  Delete(":orgId/members/:accountId"),
@@ -182,7 +182,7 @@ __decorate([
182
182
  HttpCode(204),
183
183
  __param(0, CurrentPrincipal()),
184
184
  __param(1, CurrentOrg()),
185
- __param(2, Param("accountId"))
185
+ __param(2, ZParam(MemberParamsDto))
186
186
  ], OrgsController.prototype, "removeMember", null);
187
187
  __decorate([
188
188
  Post(":orgId/service-tokens"),
@@ -4,6 +4,32 @@ export declare const OrgUpdateBody: z.ZodObject<{
4
4
  name: z.ZodOptional<z.ZodString>;
5
5
  slug: z.ZodOptional<z.ZodString>;
6
6
  }, z.core.$strip>;
7
+ /** `POST /api/v1/orgs/:orgId/invitations`: the role invited (never owner) and the link's life. */
8
+ export declare const InvitationCreateBody: z.ZodObject<{
9
+ role: z.ZodEnum<{
10
+ admin: "admin";
11
+ guest: "guest";
12
+ member: "member";
13
+ }>;
14
+ expiresInHours: z.ZodOptional<z.ZodNumber>;
15
+ }, z.core.$strip>;
16
+ /** `DELETE /api/v1/orgs/:orgId/invitations/:id`. */
17
+ export declare const InvitationIdParams: z.ZodObject<{
18
+ id: z.ZodString;
19
+ }, z.core.$strip>;
20
+ /** `PATCH` / `DELETE /api/v1/orgs/:orgId/members/:accountId`. */
21
+ export declare const MemberParams: z.ZodObject<{
22
+ accountId: z.ZodString;
23
+ }, z.core.$strip>;
24
+ /** `PATCH /api/v1/orgs/:orgId/members/:accountId`. */
25
+ export declare const MemberRoleBody: z.ZodObject<{
26
+ role: z.ZodEnum<{
27
+ admin: "admin";
28
+ guest: "guest";
29
+ member: "member";
30
+ owner: "owner";
31
+ }>;
32
+ }, z.core.$strip>;
7
33
  /** One org network allowance as the routes and Platform operations return it. */
8
34
  export interface NetworkAllowanceView {
9
35
  id: string;
@@ -1,9 +1,22 @@
1
1
  import { z } from "zod";
2
+ import { INVITABLE_ROLES, MAX_INVITATION_HOURS } from "./invitations.service.js";
3
+ import { ORG_ROLES } from "./roles.js";
2
4
  import { OrgSettingsPatchSchema } from "./settings.service.js";
3
5
  export const OrgUpdateBody = z.object({
4
6
  name: z.string().min(1).max(100).optional(),
5
7
  slug: z.string().min(1).max(40).optional(),
6
8
  });
9
+ /** `POST /api/v1/orgs/:orgId/invitations`: the role invited (never owner) and the link's life. */
10
+ export const InvitationCreateBody = z.object({
11
+ role: z.enum(INVITABLE_ROLES),
12
+ expiresInHours: z.number().int().min(1).max(MAX_INVITATION_HOURS).optional(),
13
+ });
14
+ /** `DELETE /api/v1/orgs/:orgId/invitations/:id`. */
15
+ export const InvitationIdParams = z.object({ id: z.string().min(1).max(100) });
16
+ /** `PATCH` / `DELETE /api/v1/orgs/:orgId/members/:accountId`. */
17
+ export const MemberParams = z.object({ accountId: z.string().min(1).max(100) });
18
+ /** `PATCH /api/v1/orgs/:orgId/members/:accountId`. */
19
+ export const MemberRoleBody = z.object({ role: z.enum(ORG_ROLES) });
7
20
  /** The view of a stored allowance: who added it stays in the audit log. */
8
21
  export function networkAllowanceView(a) {
9
22
  return { id: a.id, entry: a.entry, createdAt: a.createdAt };
@@ -13,6 +26,15 @@ export const ORG_ROUTES = [
13
26
  { route: "GET /api/v1/orgs/:orgId" },
14
27
  { route: "PATCH /api/v1/orgs/:orgId", body: OrgUpdateBody },
15
28
  { route: "GET /api/v1/orgs/:orgId/members" },
29
+ {
30
+ route: "PATCH /api/v1/orgs/:orgId/members/:accountId",
31
+ params: MemberParams,
32
+ body: MemberRoleBody,
33
+ },
34
+ { route: "DELETE /api/v1/orgs/:orgId/members/:accountId", params: MemberParams },
35
+ { route: "POST /api/v1/orgs/:orgId/invitations", body: InvitationCreateBody },
36
+ { route: "GET /api/v1/orgs/:orgId/invitations" },
37
+ { route: "DELETE /api/v1/orgs/:orgId/invitations/:id", params: InvitationIdParams },
16
38
  { route: "GET /api/v1/orgs/:orgId/network-allowances" },
17
39
  ];
18
40
  export const ORG_SETTINGS_ROUTES = [
@@ -0,0 +1,67 @@
1
+ import type { ConnectorAuth } from "../tools/credentials.js";
2
+ import type { PersonFieldSpec } from "./person-fields.js";
3
+ /**
4
+ * The person fields of a connector (platform web parity ruling R3). Credentials are not in a
5
+ * connector's `endpointSchema` (`endpointCredentialIssues` refuses them there), so the secret
6
+ * fields come from the auth method (`tools/credentials.ts`), by the paths of the create body:
7
+ * - `bearer` / `api_key`: `credential.token`;
8
+ * - `basic`: `credential.username`, `credential.password`;
9
+ * - `oauth_client`, `oauth_code` with a manual client: `client.clientSecret` (the client id stays
10
+ * a param; required for the client credentials flow, optional for a public code client).
11
+ *
12
+ * `none`, a dynamically registered client and custom `headers` have none: header names come from
13
+ * the auth preset (text an admin or the model wrote), never a card label, so header credentials
14
+ * are entered on the web. Labels are fixed, in both languages; every schema is a non-empty string.
15
+ */
16
+ export declare function connectorPersonFields(auth: ConnectorAuth, stored: ReadonlySet<string>): PersonFieldSpec[];
17
+ /**
18
+ * The credential value the create, credential and install bodies take, from the person's entered
19
+ * values (by the paths of {@link connectorPersonFields}, under `prefix`) and the model's client
20
+ * id: `{ token }`, `{ username, password }`, or the OAuth client `{ clientId, clientSecret? }`.
21
+ * Undefined when nothing was entered and no client given (the body then carries none).
22
+ */
23
+ export declare function connectorCredential(auth: ConnectorAuth, entered: Readonly<Record<string, string>>, clientId: string | undefined, prefix?: string): Record<string, string> | undefined;
24
+ /** A connector template whose connector a write creates: its id, card name and auth method. */
25
+ export interface TemplateTarget {
26
+ id: string;
27
+ /** The template's display name (from the plugin) in both languages, for the card labels. */
28
+ name: {
29
+ zh: string;
30
+ en: string;
31
+ };
32
+ auth: ConnectorAuth;
33
+ }
34
+ /**
35
+ * The person fields of connectors made from templates (the catalog install, the missing
36
+ * connectors of an installed plugin): each template's {@link connectorPersonFields} under
37
+ * `connectors.<templateId>.`, labelled `<template name>: <label>`.
38
+ */
39
+ export declare function templatePersonFields(templates: readonly TemplateTarget[]): PersonFieldSpec[];
40
+ /** The model's non-secret input of one template's connector (a Platform operation param). */
41
+ export interface TemplateParams {
42
+ name?: string | undefined;
43
+ slug?: string | undefined;
44
+ endpoint?: Record<string, unknown> | undefined;
45
+ client?: {
46
+ clientId: string;
47
+ } | undefined;
48
+ }
49
+ /**
50
+ * One template's connector input as the install and configure bodies take it
51
+ * (`CatalogConnectorInput`): the model's params with the person's entered values (under
52
+ * `connectors.<templateId>.`) as `credential` or the OAuth client's `clientSecret`.
53
+ */
54
+ export declare function templateConnectorInput(t: TemplateTarget, params: TemplateParams | undefined, entered: Readonly<Record<string, string>>): Record<string, unknown>;
55
+ /**
56
+ * Why a write cannot ask the person for a connector's credential on the card, or null: custom
57
+ * header credentials (their names come from the auth preset) are entered on the web.
58
+ */
59
+ export declare function headersWebOnly(auth: ConnectorAuth, where: string): string | null;
60
+ /**
61
+ * Why a write's OAuth client param does not fit the auth method, or null: an OAuth client the
62
+ * person enters a secret for (oauth_client, oauth_code with a manual client) needs its id in
63
+ * `client`; any other auth method takes no client (refused rather than ignored).
64
+ */
65
+ export declare function clientProblem(auth: ConnectorAuth, client: {
66
+ clientId: string;
67
+ } | undefined, where: string): string | null;
@@ -0,0 +1,129 @@
1
+ /** The fixed card labels of connector credentials. */
2
+ const LABELS = {
3
+ token: { zh: "令牌", en: "Token" },
4
+ username: { zh: "用户名", en: "Username" },
5
+ password: { zh: "密码", en: "Password" },
6
+ clientSecret: { zh: "客户端密钥", en: "Client secret" },
7
+ };
8
+ /**
9
+ * The person fields of a connector (platform web parity ruling R3). Credentials are not in a
10
+ * connector's `endpointSchema` (`endpointCredentialIssues` refuses them there), so the secret
11
+ * fields come from the auth method (`tools/credentials.ts`), by the paths of the create body:
12
+ * - `bearer` / `api_key`: `credential.token`;
13
+ * - `basic`: `credential.username`, `credential.password`;
14
+ * - `oauth_client`, `oauth_code` with a manual client: `client.clientSecret` (the client id stays
15
+ * a param; required for the client credentials flow, optional for a public code client).
16
+ *
17
+ * `none`, a dynamically registered client and custom `headers` have none: header names come from
18
+ * the auth preset (text an admin or the model wrote), never a card label, so header credentials
19
+ * are entered on the web. Labels are fixed, in both languages; every schema is a non-empty string.
20
+ */
21
+ export function connectorPersonFields(auth, stored) {
22
+ const field = (path, label, required, maxLength) => ({
23
+ path,
24
+ label,
25
+ multiline: false,
26
+ required,
27
+ isSet: stored.has(path),
28
+ schema: { type: "string", minLength: 1, ...(maxLength !== undefined && { maxLength }) },
29
+ });
30
+ switch (auth.type) {
31
+ case "bearer":
32
+ case "api_key":
33
+ return [field("credential.token", LABELS.token, true)];
34
+ case "basic":
35
+ return [
36
+ field("credential.username", LABELS.username, true),
37
+ field("credential.password", LABELS.password, true),
38
+ ];
39
+ case "oauth_client":
40
+ // the bound of the create's OAuth client parse (`OAuthClientCredential`)
41
+ return [field("client.clientSecret", LABELS.clientSecret, true, 4000)];
42
+ case "oauth_code":
43
+ return auth.client === "manual"
44
+ ? [field("client.clientSecret", LABELS.clientSecret, false, 4000)]
45
+ : [];
46
+ default:
47
+ return [];
48
+ }
49
+ }
50
+ /**
51
+ * The credential value the create, credential and install bodies take, from the person's entered
52
+ * values (by the paths of {@link connectorPersonFields}, under `prefix`) and the model's client
53
+ * id: `{ token }`, `{ username, password }`, or the OAuth client `{ clientId, clientSecret? }`.
54
+ * Undefined when nothing was entered and no client given (the body then carries none).
55
+ */
56
+ export function connectorCredential(auth, entered, clientId, prefix = "") {
57
+ const at = (p) => entered[`${prefix}${p}`];
58
+ if (auth.type === "oauth_client" || auth.type === "oauth_code") {
59
+ if (clientId === undefined)
60
+ return undefined;
61
+ const secret = at("client.clientSecret");
62
+ return { clientId, ...(secret !== undefined && { clientSecret: secret }) };
63
+ }
64
+ if (auth.type === "bearer" || auth.type === "api_key") {
65
+ const token = at("credential.token");
66
+ return token === undefined ? undefined : { token };
67
+ }
68
+ if (auth.type === "basic") {
69
+ const username = at("credential.username");
70
+ const password = at("credential.password");
71
+ if (username === undefined && password === undefined)
72
+ return undefined;
73
+ return {
74
+ ...(username !== undefined && { username }),
75
+ ...(password !== undefined && { password }),
76
+ };
77
+ }
78
+ return undefined;
79
+ }
80
+ /**
81
+ * The person fields of connectors made from templates (the catalog install, the missing
82
+ * connectors of an installed plugin): each template's {@link connectorPersonFields} under
83
+ * `connectors.<templateId>.`, labelled `<template name>: <label>`.
84
+ */
85
+ export function templatePersonFields(templates) {
86
+ return templates.flatMap((t) => connectorPersonFields(t.auth, new Set()).map((f) => ({
87
+ ...f,
88
+ path: `connectors.${t.id}.${f.path}`,
89
+ label: { zh: `${t.name.zh}:${f.label.zh}`, en: `${t.name.en}: ${f.label.en}` },
90
+ })));
91
+ }
92
+ /**
93
+ * One template's connector input as the install and configure bodies take it
94
+ * (`CatalogConnectorInput`): the model's params with the person's entered values (under
95
+ * `connectors.<templateId>.`) as `credential` or the OAuth client's `clientSecret`.
96
+ */
97
+ export function templateConnectorInput(t, params, entered) {
98
+ const { client, ...rest } = params ?? {};
99
+ const value = connectorCredential(t.auth, entered, client?.clientId, `connectors.${t.id}.`);
100
+ const oauth = t.auth.type === "oauth_client" || t.auth.type === "oauth_code";
101
+ return {
102
+ ...rest,
103
+ ...(value !== undefined && (oauth ? { client: value } : { credential: value })),
104
+ };
105
+ }
106
+ /**
107
+ * Why a write cannot ask the person for a connector's credential on the card, or null: custom
108
+ * header credentials (their names come from the auth preset) are entered on the web.
109
+ */
110
+ export function headersWebOnly(auth, where) {
111
+ return auth.type === "headers"
112
+ ? `${where} authenticates with custom headers, whose values the confirmation card cannot ask for; the person enters them on the web.`
113
+ : null;
114
+ }
115
+ /**
116
+ * Why a write's OAuth client param does not fit the auth method, or null: an OAuth client the
117
+ * person enters a secret for (oauth_client, oauth_code with a manual client) needs its id in
118
+ * `client`; any other auth method takes no client (refused rather than ignored).
119
+ */
120
+ export function clientProblem(auth, client, where) {
121
+ const needs = auth.type === "oauth_client" || (auth.type === "oauth_code" && auth.client === "manual");
122
+ if (needs && client === undefined) {
123
+ return `${where} uses an OAuth client: pass its id in client (the person enters the client secret on the confirmation card)`;
124
+ }
125
+ if (!needs && client !== undefined) {
126
+ return `${where} takes no OAuth client (auth ${auth.type}${auth.type === "oauth_code" ? " with a registered client" : ""}); leave client out`;
127
+ }
128
+ return null;
129
+ }
@@ -29,22 +29,7 @@ export const PLATFORM_EXCLUSIONS = [
29
29
  {
30
30
  route: "GET /api/v1/admin/extensions/:name/org-overrides",
31
31
  category: "secret",
32
- reason: "Lists every org's config copy of an extension: cross-org config state",
33
- },
34
- {
35
- route: "GET /api/v1/admin/extensions/:name/config",
36
- category: "secret",
37
- reason: "Returns deployment config that can include secret fields",
38
- },
39
- {
40
- route: "PUT /api/v1/admin/extensions/:name/config",
41
- category: "secret",
42
- reason: "Writes deployment config that can include secret fields",
43
- },
44
- {
45
- route: "DELETE /api/v1/admin/extensions/:name/config",
46
- category: "secret",
47
- reason: "Clears deployment config including secret values; done on the web",
32
+ reason: "Delivers other orgs' config copies of an extension (which differ, which secrets each holds) to the super admin's browser; an agent works in its own org",
48
33
  },
49
34
  {
50
35
  route: "POST /api/v1/admin/extensions/:name/approve",
@@ -180,21 +165,6 @@ export const PLATFORM_EXCLUSIONS = [
180
165
  category: "transport",
181
166
  reason: "Serves icon image bytes",
182
167
  },
183
- {
184
- route: "POST /api/v1/orgs/:orgId/catalog/:itemId/install",
185
- category: "secret",
186
- reason: "Install body carries connector credentials, client secrets and extension config entered by a person",
187
- },
188
- {
189
- route: "POST /api/v1/orgs/:orgId/catalog/:itemId/connectors",
190
- category: "secret",
191
- reason: "Body carries connector credentials and client secrets entered by a person",
192
- },
193
- {
194
- route: "POST /api/v1/orgs/:orgId/connector-templates/:templateId/connectors",
195
- category: "secret",
196
- reason: "Body carries connector credentials and client secrets entered by a person",
197
- },
198
168
  {
199
169
  route: "POST /api/v1/orgs/:orgId/catalog-requests/network",
200
170
  category: "human-only",
@@ -215,31 +185,6 @@ export const PLATFORM_EXCLUSIONS = [
215
185
  category: "human-only",
216
186
  reason: "Decides an org's catalog request as super admin",
217
187
  },
218
- {
219
- route: "PUT /api/v1/orgs/:orgId/extensions/:extension",
220
- category: "secret",
221
- reason: "Org extension config may hold secret fields",
222
- },
223
- {
224
- route: "GET /api/v1/orgs/:orgId/extensions/:extension/overrides",
225
- category: "secret",
226
- reason: "The org's copy of an extension's deployment config, with secret fields as set or not",
227
- },
228
- {
229
- route: "PUT /api/v1/orgs/:orgId/extensions/:extension/overrides",
230
- category: "secret",
231
- reason: "Saves the org's config copy, including the org's own secrets entered in the same save",
232
- },
233
- {
234
- route: "DELETE /api/v1/orgs/:orgId/extensions/:extension/overrides",
235
- category: "secret",
236
- reason: "Drops the org's config copy and its secrets; part of the config-copy lifecycle on the web",
237
- },
238
- {
239
- route: "POST /api/v1/orgs/:orgId/extensions/:extension/overrides/take",
240
- category: "secret",
241
- reason: "Starts an org config copy whose secrets a person enters on the web",
242
- },
243
188
  // org-uploads
244
189
  {
245
190
  route: "POST /api/v1/orgs/:orgId/catalog/uploads/file",
@@ -252,21 +197,6 @@ export const PLATFORM_EXCLUSIONS = [
252
197
  reason: "Confirms an upload review, an approval decision",
253
198
  },
254
199
  // channels
255
- {
256
- route: "GET /api/v1/orgs/:orgId/channels/schema/:plugin",
257
- category: "internal",
258
- reason: "The config form schema of the create and credential routes, which stay on the web; an agent has no use for it",
259
- },
260
- {
261
- route: "POST /api/v1/orgs/:orgId/channels",
262
- category: "secret",
263
- reason: "Creates a channel connection with app secrets",
264
- },
265
- {
266
- route: "POST /api/v1/orgs/:orgId/channels/:connectionId/guide-ack",
267
- category: "human-only",
268
- reason: "A person confirms they updated the app on the third-party platform after a setup guide changed; only that person knows it was done",
269
- },
270
200
  // attachments
271
201
  {
272
202
  route: "GET /api/v1/orgs/:orgId/attachments/limits",
@@ -488,6 +418,11 @@ export const PLATFORM_EXCLUSIONS = [
488
418
  category: "secret",
489
419
  reason: "Returns a generated initial password once, on the web, to the person who approved the account creation",
490
420
  },
421
+ {
422
+ route: "POST /api/v1/orgs/:orgId/approvals/:approvalId/invitation-link",
423
+ category: "secret",
424
+ reason: "Returns an invitation link once, on the web, to the person who approved the orgs.invite call",
425
+ },
491
426
  { route: "POST /api/v1/auth/login", category: "human-only", reason: "Password login" },
492
427
  { route: "POST /api/v1/auth/refresh", category: "human-only", reason: "Rotates a refresh token" },
493
428
  { route: "POST /api/v1/auth/logout", category: "human-only", reason: "Ends the login session" },
@@ -566,21 +501,6 @@ export const PLATFORM_EXCLUSIONS = [
566
501
  category: "human-only",
567
502
  reason: "Adds and removes org members from the directory; only an admin, by hand, starts it",
568
503
  },
569
- {
570
- route: "POST /api/v1/orgs/:orgId/invitations",
571
- category: "human-only",
572
- reason: "Invites a person into the org",
573
- },
574
- {
575
- route: "GET /api/v1/orgs/:orgId/invitations",
576
- category: "human-only",
577
- reason: "Lists invitations with their tokens",
578
- },
579
- {
580
- route: "DELETE /api/v1/orgs/:orgId/invitations/:id",
581
- category: "human-only",
582
- reason: "Revokes an invitation",
583
- },
584
504
  {
585
505
  route: "GET /api/v1/invitations/:token",
586
506
  category: "human-only",
@@ -612,16 +532,6 @@ export const PLATFORM_EXCLUSIONS = [
612
532
  category: "human-only",
613
533
  reason: "Removes the caller from the org",
614
534
  },
615
- {
616
- route: "PATCH /api/v1/orgs/:orgId/members/:accountId",
617
- category: "human-only",
618
- reason: "Changes a member's role",
619
- },
620
- {
621
- route: "DELETE /api/v1/orgs/:orgId/members/:accountId",
622
- category: "human-only",
623
- reason: "Removes a member from the org",
624
- },
625
535
  {
626
536
  route: "POST /api/v1/orgs/:orgId/service-tokens",
627
537
  category: "human-only",
@@ -701,46 +611,11 @@ export const PLATFORM_EXCLUSIONS = [
701
611
  category: "internal",
702
612
  reason: "Renders a remote server's prompt into text for the web input box, for the person to send; it calls the server with the person's own credential",
703
613
  },
704
- {
705
- route: "GET /api/v1/orgs/:orgId/connectors/kinds",
706
- category: "internal",
707
- reason: "The protocols the web's create-connector form offers; creating a connector stays on the web (secret credentials)",
708
- },
709
- {
710
- route: "POST /api/v1/orgs/:orgId/connectors",
711
- category: "secret",
712
- reason: "Creates a connector whose endpoint config can carry credentials",
713
- },
714
- {
715
- route: "POST /api/v1/orgs/:orgId/connectors/preview",
716
- category: "secret",
717
- reason: "Preview body carries a connector credential entered by a person",
718
- },
719
- {
720
- route: "PATCH /api/v1/orgs/:orgId/connectors/:connectorId",
721
- category: "secret",
722
- reason: "Edits connector endpoint config that can carry credentials",
723
- },
724
- {
725
- route: "POST /api/v1/orgs/:orgId/connectors/:connectorId/guide-ack",
726
- category: "human-only",
727
- reason: "A person confirms they updated the app on the third-party platform after a connector template's setup guide changed; only that person knows it was done",
728
- },
729
614
  {
730
615
  route: "POST /api/v1/orgs/:orgId/connectors/:connectorId/tools/:name/review",
731
616
  category: "human-only",
732
617
  reason: "Reviews a connector tool change, an approval decision",
733
618
  },
734
- {
735
- route: "PUT /api/v1/orgs/:orgId/connectors/:connectorId/credentials/org",
736
- category: "secret",
737
- reason: "Writes the org's connector credentials",
738
- },
739
- {
740
- route: "PUT /api/v1/orgs/:orgId/connectors/:connectorId/credentials/me",
741
- category: "secret",
742
- reason: "Writes the caller's connector credentials",
743
- },
744
619
  {
745
620
  route: "GET /api/v1/orgs/:orgId/connectors/:connectorId/tool-policies/me",
746
621
  category: "internal",
@@ -751,21 +626,11 @@ export const PLATFORM_EXCLUSIONS = [
751
626
  category: "human-only",
752
627
  reason: "A member's own tool policies decide what agents may call with their connection without asking; an agent must never loosen them for itself",
753
628
  },
754
- {
755
- route: "DELETE /api/v1/orgs/:orgId/connectors/:connectorId/credentials/me",
756
- category: "secret",
757
- reason: "Deletes the caller's connector credentials",
758
- },
759
629
  {
760
630
  route: "GET /api/v1/orgs/:orgId/tools/extensions",
761
631
  category: "internal",
762
632
  reason: "Display list of the agent form's tools picker; extensions.tools gives an agent the same facts",
763
633
  },
764
- {
765
- route: "POST /api/v1/orgs/:orgId/connectors/:connectorId/connect",
766
- category: "secret",
767
- reason: "Starts a connector OAuth flow",
768
- },
769
634
  {
770
635
  route: "GET /api/v1/oauth/callback",
771
636
  category: "secret",
@@ -11,5 +11,6 @@ export const PLATFORM_METHOD = [
11
11
  "4. An operation you may not call is not a dead end: its reason says who can (an org admin, the super admin) and whether a request operation exists; offer that.",
12
12
  "5. Errors say what to do next; follow them.",
13
13
  '6. When unsure how the platform works, use action "read" for the docs before acting.',
14
+ "Secret fields (API keys, tokens, passwords, credentials) never go in params: list their dot paths in askPerson and the person types them on the confirmation card; list the stored secrets to remove in clearSecrets. Required secrets without a stored value are asked even when not listed. The result names each field the person entered, never its value. A secret that appeared in the conversation counts as leaked: tell the person to rotate it.",
14
15
  'Find an operation with "browse" (a domain) or "search": each lists its input keys in "params" ("?" marks an optional key, an id key takes the id field of the matching list or get result). "describe" gives the types, bounds and an example; describe before a call whose params you are unsure of, and never guess a key that params does not list.',
15
16
  ].join("\n");