@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
@@ -77,7 +77,6 @@ declare const CreateBody: z.ZodObject<{
77
77
  credential: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
78
78
  git: z.ZodOptional<z.ZodType<import("@capybara-hq/plugin-sdk").GitSource, unknown, z.core.$ZodTypeInternals<import("@capybara-hq/plugin-sdk").GitSource, unknown>>>;
79
79
  }, z.core.$strict>;
80
- /** 预览(Ruling A20):与创建相同的连接器 / 端点 / 认证 / 凭据,认证可缺省(只读端点描述,不列工具)。 */
81
80
  declare const PreviewBody: z.ZodObject<{
82
81
  name: z.ZodOptional<z.ZodString>;
83
82
  slug: z.ZodOptional<z.ZodString>;
@@ -147,12 +146,6 @@ declare const PreviewBody: z.ZodObject<{
147
146
  }, z.core.$strict>], "type">>;
148
147
  credential: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
149
148
  }, z.core.$strict>;
150
- declare const ReviewBody: z.ZodObject<{
151
- action: z.ZodEnum<{
152
- approve: "approve";
153
- reject: "reject";
154
- }>;
155
- }, z.core.$strict>;
156
149
  declare const UpdateBody: z.ZodObject<{
157
150
  name: z.ZodOptional<z.ZodString>;
158
151
  status: z.ZodOptional<z.ZodEnum<{
@@ -173,6 +166,12 @@ declare const UpdateBody: z.ZodObject<{
173
166
  allowUnannotated: z.ZodOptional<z.ZodBoolean>;
174
167
  useForGit: z.ZodOptional<z.ZodBoolean>;
175
168
  }, z.core.$strict>;
169
+ declare const ReviewBody: z.ZodObject<{
170
+ action: z.ZodEnum<{
171
+ approve: "approve";
172
+ reject: "reject";
173
+ }>;
174
+ }, z.core.$strict>;
176
175
  /** The member's Permissions sheet: their tool policies and the git push part (null without git). */
177
176
  interface MemberPolicySheet {
178
177
  tools: MemberToolPolicyView[];
@@ -7,7 +7,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
- import { ConnectorAuthSchema, GitSourceSchema } from "@capybara-hq/plugin-sdk";
11
10
  import { Controller, Delete, Get, HttpCode, Inject, Param, Patch, Post, Put } from "@nestjs/common";
12
11
  import { z } from "zod";
13
12
  import { orgIconScope, PluginIcons } from "../extensions/plugin-icons.js";
@@ -18,7 +17,7 @@ import { ZBody } from "../infra/validation/zod-params.js";
18
17
  import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
19
18
  import { can } from "../orgs/roles.js";
20
19
  import { ConnectorAccountPolicies, } from "./connector-account-policies.js";
21
- import { ConnectorGuideAckSchema, CredentialValue, GitPushPolicyBody, MemberToolPoliciesBody, } from "./connectors.schemas.js";
20
+ import { ConnectorCreateSchema, ConnectorGuideAckSchema, ConnectorPreviewSchema, ConnectorUpdateSchema, CredentialValue, GitPushPolicyBody, MemberToolPoliciesBody, } from "./connectors.schemas.js";
22
21
  import { ConnectorsService, } from "./connectors.service.js";
23
22
  import { publicEndpoint } from "./endpoint.js";
24
23
  import { callbackUrl } from "./oauth/flow-paths.js";
@@ -39,49 +38,10 @@ function forViewer(org, c) {
39
38
  }
40
39
  return view;
41
40
  }
42
- const CreateBody = z
43
- .object({
44
- name: z.string().trim().min(1).max(80),
45
- slug: z.string().max(24).optional(),
46
- connector: z.string().min(1).max(100),
47
- endpoint: z.record(z.string(), z.unknown()),
48
- auth: ConnectorAuthSchema,
49
- credential: CredentialValue.optional(),
50
- /** The git hosts the credential serves in sandboxes (sandbox git credentials spec §6.1). */
51
- git: GitSourceSchema.optional(),
52
- })
53
- .strict();
54
- /** 预览(Ruling A20):与创建相同的连接器 / 端点 / 认证 / 凭据,认证可缺省(只读端点描述,不列工具)。 */
55
- const PreviewBody = z
56
- .object({
57
- name: z.string().trim().min(1).max(80).optional(),
58
- slug: z.string().max(24).optional(),
59
- connector: z.string().min(1).max(100),
60
- endpoint: z.record(z.string(), z.unknown()),
61
- auth: ConnectorAuthSchema.optional(),
62
- credential: CredentialValue.optional(),
63
- })
64
- .strict();
65
- const ToolPatch = z
66
- .object({
67
- status: z.enum(["enabled", "disabled"]).optional(),
68
- defaultPolicy: z.enum(["allow", "ask", "deny"]).optional(),
69
- })
70
- .strict();
41
+ const CreateBody = ConnectorCreateSchema;
42
+ const PreviewBody = ConnectorPreviewSchema;
43
+ const UpdateBody = ConnectorUpdateSchema;
71
44
  const ReviewBody = z.object({ action: z.enum(["approve", "reject"]) }).strict();
72
- const UpdateBody = z
73
- .object({
74
- name: z.string().trim().min(1).max(80).optional(),
75
- status: z.enum(["active", "disabled"]).optional(),
76
- tools: z
77
- .record(z.string().max(200), ToolPatch)
78
- .refine((v) => Object.keys(v).length <= 1000, { message: "Too many tools" })
79
- .optional(),
80
- allowUnannotated: z.boolean().optional(),
81
- /** Use an org-credential connector for git in sandboxes (spec 2026-11-12 §6.2). */
82
- useForGit: z.boolean().optional(),
83
- })
84
- .strict();
85
45
  class ConnectorCreateBody extends createZodDto(CreateBody, "ConnectorCreateBody") {
86
46
  }
87
47
  class ConnectorPreviewBody extends createZodDto(PreviewBody, "ConnectorPreviewBody") {
@@ -2,7 +2,8 @@ import { z } from "zod";
2
2
  import type { RouteSchemas } from "../platform/route-schemas.js";
3
3
  /**
4
4
  * A credential value: `Credentials.validate` checks its shape by auth method (values are never
5
- * echoed); this only bounds its size.
5
+ * echoed); this only bounds its size. A secret (`secret()` meta, ruling R2): a Platform operation
6
+ * never takes it as a param; the person enters it on the confirmation card.
6
7
  */
7
8
  export declare const CredentialValue: z.ZodRecord<z.ZodString, z.ZodUnknown>;
8
9
  /** 「我已更新应用」: the admin drift hash of the connector template guide the person was shown. */
@@ -25,6 +26,174 @@ export declare const GitPushPolicyBody: z.ZodObject<{
25
26
  deny: "deny";
26
27
  }>;
27
28
  }, z.core.$strict>;
29
+ /** `POST …/connectors`: a custom connector with its endpoint, auth method and credential. */
30
+ export declare const ConnectorCreateSchema: z.ZodObject<{
31
+ name: z.ZodString;
32
+ slug: z.ZodOptional<z.ZodString>;
33
+ connector: z.ZodString;
34
+ endpoint: z.ZodRecord<z.ZodString, z.ZodUnknown>;
35
+ auth: z.ZodDiscriminatedUnion<[z.ZodObject<{
36
+ type: z.ZodLiteral<"none">;
37
+ }, z.core.$strict>, z.ZodObject<{
38
+ type: z.ZodLiteral<"bearer">;
39
+ ownership: z.ZodEnum<{
40
+ org: "org";
41
+ personal: "personal";
42
+ }>;
43
+ }, z.core.$strict>, z.ZodObject<{
44
+ type: z.ZodLiteral<"api_key">;
45
+ ownership: z.ZodEnum<{
46
+ org: "org";
47
+ personal: "personal";
48
+ }>;
49
+ in: z.ZodEnum<{
50
+ header: "header";
51
+ query: "query";
52
+ }>;
53
+ name: z.ZodString;
54
+ }, z.core.$strict>, z.ZodObject<{
55
+ type: z.ZodLiteral<"basic">;
56
+ ownership: z.ZodEnum<{
57
+ org: "org";
58
+ personal: "personal";
59
+ }>;
60
+ }, z.core.$strict>, z.ZodObject<{
61
+ type: z.ZodLiteral<"headers">;
62
+ ownership: z.ZodEnum<{
63
+ org: "org";
64
+ personal: "personal";
65
+ }>;
66
+ names: z.ZodArray<z.ZodString>;
67
+ }, z.core.$strict>, z.ZodObject<{
68
+ type: z.ZodLiteral<"oauth_code">;
69
+ ownership: z.ZodLiteral<"personal">;
70
+ discovery: z.ZodEnum<{
71
+ manual: "manual";
72
+ mcp: "mcp";
73
+ }>;
74
+ authorizationUrl: z.ZodOptional<z.ZodURL>;
75
+ tokenUrl: z.ZodOptional<z.ZodURL>;
76
+ scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
77
+ client: z.ZodEnum<{
78
+ dcr: "dcr";
79
+ manual: "manual";
80
+ }>;
81
+ tokenAuthMethod: z.ZodOptional<z.ZodEnum<{
82
+ client_secret_basic: "client_secret_basic";
83
+ client_secret_post: "client_secret_post";
84
+ }>>;
85
+ tokenTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
86
+ }, z.core.$strict>, z.ZodObject<{
87
+ type: z.ZodLiteral<"oauth_client">;
88
+ ownership: z.ZodLiteral<"org">;
89
+ tokenUrl: z.ZodURL;
90
+ scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
91
+ tokenAuthMethod: z.ZodOptional<z.ZodEnum<{
92
+ client_secret_basic: "client_secret_basic";
93
+ client_secret_post: "client_secret_post";
94
+ }>>;
95
+ tokenTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
96
+ }, z.core.$strict>], "type">;
97
+ credential: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
98
+ git: z.ZodOptional<z.ZodType<import("@capybara-hq/plugin-sdk").GitSource, unknown, z.core.$ZodTypeInternals<import("@capybara-hq/plugin-sdk").GitSource, unknown>>>;
99
+ }, z.core.$strict>;
100
+ /**
101
+ * `POST …/connectors/preview` (ruling A20): the create's connector, endpoint, auth and credential;
102
+ * the auth may be left out (reads the endpoint description only, lists no tools).
103
+ */
104
+ export declare const ConnectorPreviewSchema: z.ZodObject<{
105
+ name: z.ZodOptional<z.ZodString>;
106
+ slug: z.ZodOptional<z.ZodString>;
107
+ connector: z.ZodString;
108
+ endpoint: z.ZodRecord<z.ZodString, z.ZodUnknown>;
109
+ auth: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
110
+ type: z.ZodLiteral<"none">;
111
+ }, z.core.$strict>, z.ZodObject<{
112
+ type: z.ZodLiteral<"bearer">;
113
+ ownership: z.ZodEnum<{
114
+ org: "org";
115
+ personal: "personal";
116
+ }>;
117
+ }, z.core.$strict>, z.ZodObject<{
118
+ type: z.ZodLiteral<"api_key">;
119
+ ownership: z.ZodEnum<{
120
+ org: "org";
121
+ personal: "personal";
122
+ }>;
123
+ in: z.ZodEnum<{
124
+ header: "header";
125
+ query: "query";
126
+ }>;
127
+ name: z.ZodString;
128
+ }, z.core.$strict>, z.ZodObject<{
129
+ type: z.ZodLiteral<"basic">;
130
+ ownership: z.ZodEnum<{
131
+ org: "org";
132
+ personal: "personal";
133
+ }>;
134
+ }, z.core.$strict>, z.ZodObject<{
135
+ type: z.ZodLiteral<"headers">;
136
+ ownership: z.ZodEnum<{
137
+ org: "org";
138
+ personal: "personal";
139
+ }>;
140
+ names: z.ZodArray<z.ZodString>;
141
+ }, z.core.$strict>, z.ZodObject<{
142
+ type: z.ZodLiteral<"oauth_code">;
143
+ ownership: z.ZodLiteral<"personal">;
144
+ discovery: z.ZodEnum<{
145
+ manual: "manual";
146
+ mcp: "mcp";
147
+ }>;
148
+ authorizationUrl: z.ZodOptional<z.ZodURL>;
149
+ tokenUrl: z.ZodOptional<z.ZodURL>;
150
+ scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
151
+ client: z.ZodEnum<{
152
+ dcr: "dcr";
153
+ manual: "manual";
154
+ }>;
155
+ tokenAuthMethod: z.ZodOptional<z.ZodEnum<{
156
+ client_secret_basic: "client_secret_basic";
157
+ client_secret_post: "client_secret_post";
158
+ }>>;
159
+ tokenTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
160
+ }, z.core.$strict>, z.ZodObject<{
161
+ type: z.ZodLiteral<"oauth_client">;
162
+ ownership: z.ZodLiteral<"org">;
163
+ tokenUrl: z.ZodURL;
164
+ scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
165
+ tokenAuthMethod: z.ZodOptional<z.ZodEnum<{
166
+ client_secret_basic: "client_secret_basic";
167
+ client_secret_post: "client_secret_post";
168
+ }>>;
169
+ tokenTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
170
+ }, z.core.$strict>], "type">>;
171
+ credential: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
172
+ }, z.core.$strict>;
173
+ /**
174
+ * `PATCH …/connectors/:connectorId`: rename, switch on or off, per-tool state and default policy,
175
+ * every unannotated tool to allow, and git use. No endpoint and no credential.
176
+ */
177
+ export declare const ConnectorUpdateSchema: z.ZodObject<{
178
+ name: z.ZodOptional<z.ZodString>;
179
+ status: z.ZodOptional<z.ZodEnum<{
180
+ active: "active";
181
+ disabled: "disabled";
182
+ }>>;
183
+ tools: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
184
+ status: z.ZodOptional<z.ZodEnum<{
185
+ disabled: "disabled";
186
+ enabled: "enabled";
187
+ }>>;
188
+ defaultPolicy: z.ZodOptional<z.ZodEnum<{
189
+ allow: "allow";
190
+ ask: "ask";
191
+ deny: "deny";
192
+ }>>;
193
+ }, z.core.$strict>>>;
194
+ allowUnannotated: z.ZodOptional<z.ZodBoolean>;
195
+ useForGit: z.ZodOptional<z.ZodBoolean>;
196
+ }, z.core.$strict>;
28
197
  export declare const CONNECTOR_ROUTES: readonly RouteSchemas[];
29
198
  /**
30
199
  * `PUT …/connectors/:connectorId/tool-policies/me`: the caller's own policy per tool name (null
@@ -1,11 +1,13 @@
1
+ import { ConnectorAuthSchema, GitSourceSchema, secret } from "@capybara-hq/plugin-sdk";
1
2
  import { z } from "zod";
2
3
  /**
3
4
  * A credential value: `Credentials.validate` checks its shape by auth method (values are never
4
- * echoed); this only bounds its size.
5
+ * echoed); this only bounds its size. A secret (`secret()` meta, ruling R2): a Platform operation
6
+ * never takes it as a param; the person enters it on the confirmation card.
5
7
  */
6
- export const CredentialValue = z
8
+ export const CredentialValue = secret(z
7
9
  .record(z.string().max(100), z.unknown())
8
- .refine((v) => JSON.stringify(v).length <= 16_384, { message: "Credential is too large" });
10
+ .refine((v) => JSON.stringify(v).length <= 16_384, { message: "Credential is too large" }));
9
11
  /** 「我已更新应用」: the admin drift hash of the connector template guide the person was shown. */
10
12
  export const ConnectorGuideAckSchema = z
11
13
  .object({ hash: z.string().regex(/^[0-9a-f]{64}$/) })
@@ -18,8 +20,85 @@ export const ConnectorPathParams = z.object({ connectorId: z.string().min(1) });
18
20
  * spec §7).
19
21
  */
20
22
  export const GitPushPolicyBody = z.object({ policy: z.enum(["allow", "ask", "deny"]) }).strict();
23
+ /** `POST …/connectors`: a custom connector with its endpoint, auth method and credential. */
24
+ export const ConnectorCreateSchema = z
25
+ .object({
26
+ name: z.string().trim().min(1).max(80),
27
+ slug: z.string().max(24).optional(),
28
+ connector: z.string().min(1).max(100),
29
+ endpoint: z.record(z.string(), z.unknown()),
30
+ auth: ConnectorAuthSchema,
31
+ credential: CredentialValue.optional(),
32
+ /** The git hosts the credential serves in sandboxes (sandbox git credentials spec §6.1). */
33
+ git: GitSourceSchema.optional(),
34
+ })
35
+ .strict();
36
+ /**
37
+ * `POST …/connectors/preview` (ruling A20): the create's connector, endpoint, auth and credential;
38
+ * the auth may be left out (reads the endpoint description only, lists no tools).
39
+ */
40
+ export const ConnectorPreviewSchema = z
41
+ .object({
42
+ name: z.string().trim().min(1).max(80).optional(),
43
+ slug: z.string().max(24).optional(),
44
+ connector: z.string().min(1).max(100),
45
+ endpoint: z.record(z.string(), z.unknown()),
46
+ auth: ConnectorAuthSchema.optional(),
47
+ credential: CredentialValue.optional(),
48
+ })
49
+ .strict();
50
+ const ToolPatch = z
51
+ .object({
52
+ status: z.enum(["enabled", "disabled"]).optional(),
53
+ defaultPolicy: z.enum(["allow", "ask", "deny"]).optional(),
54
+ })
55
+ .strict();
56
+ /**
57
+ * `PATCH …/connectors/:connectorId`: rename, switch on or off, per-tool state and default policy,
58
+ * every unannotated tool to allow, and git use. No endpoint and no credential.
59
+ */
60
+ export const ConnectorUpdateSchema = z
61
+ .object({
62
+ name: z.string().trim().min(1).max(80).optional(),
63
+ status: z.enum(["active", "disabled"]).optional(),
64
+ tools: z
65
+ .record(z.string().max(200), ToolPatch)
66
+ .refine((v) => Object.keys(v).length <= 1000, { message: "Too many tools" })
67
+ .optional(),
68
+ allowUnannotated: z.boolean().optional(),
69
+ /** Use an org-credential connector for git in sandboxes (spec 2026-11-12 §6.2). */
70
+ useForGit: z.boolean().optional(),
71
+ })
72
+ .strict();
21
73
  export const CONNECTOR_ROUTES = [
22
74
  { route: "GET /api/v1/orgs/:orgId/connectors" },
75
+ { route: "GET /api/v1/orgs/:orgId/connectors/kinds" },
76
+ { route: "POST /api/v1/orgs/:orgId/connectors", body: ConnectorCreateSchema },
77
+ { route: "POST /api/v1/orgs/:orgId/connectors/preview", body: ConnectorPreviewSchema },
78
+ {
79
+ route: "PATCH /api/v1/orgs/:orgId/connectors/:connectorId",
80
+ params: ConnectorPathParams,
81
+ body: ConnectorUpdateSchema,
82
+ },
83
+ {
84
+ route: "POST /api/v1/orgs/:orgId/connectors/:connectorId/guide-ack",
85
+ params: ConnectorPathParams,
86
+ body: ConnectorGuideAckSchema,
87
+ },
88
+ {
89
+ route: "PUT /api/v1/orgs/:orgId/connectors/:connectorId/credentials/org",
90
+ params: ConnectorPathParams,
91
+ body: CredentialValue,
92
+ },
93
+ {
94
+ route: "PUT /api/v1/orgs/:orgId/connectors/:connectorId/credentials/me",
95
+ params: ConnectorPathParams,
96
+ body: CredentialValue,
97
+ },
98
+ {
99
+ route: "DELETE /api/v1/orgs/:orgId/connectors/:connectorId/credentials/me",
100
+ params: ConnectorPathParams,
101
+ },
23
102
  { route: "GET /api/v1/orgs/:orgId/connectors/:connectorId", params: ConnectorPathParams },
24
103
  { route: "DELETE /api/v1/orgs/:orgId/connectors/:connectorId", params: ConnectorPathParams },
25
104
  {
@@ -1,5 +1,5 @@
1
1
  import { type AuthHint, type ConnectorOperation, type GitSource, type ToolAnnotations } from "@capybara-hq/plugin-sdk";
2
- import { type ConnectionGuideState, PluginGuides } from "../extensions/plugin-guides.js";
2
+ import { type ConnectionGuideState, type GuideAck, PluginGuides } from "../extensions/plugin-guides.js";
3
3
  import { ExtensionRegistry } from "../extensions/registry.js";
4
4
  import type { WriteActor } from "../identity/write-actor.js";
5
5
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
@@ -295,7 +295,7 @@ export declare class ConnectorsService {
295
295
  * OAuth(A16,要求 `http.publicUrl`):授权码连接器不做首次 listTools(首个成员连接后刷新),只存客户端;
296
296
  * 客户端凭据连接器用安装时取到的组织 token listTools,存客户端与 token。
297
297
  */
298
- create(orgId: string, actorAccountId: string, input: CreateConnectorInput, actorTokenId?: string): Promise<{
298
+ create(orgId: string, actorAccountId: string, input: CreateConnectorInput, actorTokenId?: string, auditDetail?: Record<string, unknown>): Promise<{
299
299
  connector: ConnectorDetail;
300
300
  issues: ToolIssue[];
301
301
  }>;
@@ -364,14 +364,24 @@ export declare class ConnectorsService {
364
364
  ackGuide(org: {
365
365
  orgId: string;
366
366
  role: OrgRole;
367
- }, connectorId: string, hash: string, actorAccountId: string, actorTokenId?: string): Promise<ConnectorDetail>;
367
+ }, connectorId: string, hash: string, actorAccountId: string, actorTokenId?: string, auditDetail?: Record<string, unknown>): Promise<ConnectorDetail>;
368
+ /**
369
+ * The setup guide a connector made from a template would be acknowledged with now (the
370
+ * template's guide in its item's latest version, with its admin drift hash). An unknown
371
+ * connector -> 404 `connector.not_found`; one without a template guide, or whose item the org's
372
+ * catalog does not show -> 404 `catalog.guide_not_found`.
373
+ */
374
+ currentGuide(org: {
375
+ orgId: string;
376
+ role: OrgRole;
377
+ }, connectorId: string): Promise<GuideAck>;
368
378
  /** The row and audit of {@link ackGuide}, in one transaction under the org lock. */
369
379
  private ackIn;
370
380
  /** The org's connectors that are not deleted (by creation time). */
371
381
  list(orgId: string): Promise<ConnectorSummary[]>;
372
382
  get(orgId: string, connectorId: string, viewerAccountId: string): Promise<ConnectorDetail>;
373
383
  /** 改名、启停连接器、工具启停与默认策略、批量把无注解工具改为 allow(`connectors.manage`)。 */
374
- update(orgId: string, connectorId: string, actorAccountId: string, patch: UpdateConnectorInput, actorTokenId?: string): Promise<ConnectorDetail>;
384
+ update(orgId: string, connectorId: string, actorAccountId: string, patch: UpdateConnectorInput, actorTokenId?: string, auditDetail?: Record<string, unknown>): Promise<ConnectorDetail>;
375
385
  /**
376
386
  * The read-only checks of {@link setGitPushPolicy} (the Platform operation's precheck): the
377
387
  * connector exists (`connector.not_found`) and declares git hosts (400 on `policy`); with
@@ -462,7 +472,7 @@ export declare class ConnectorsService {
462
472
  * 写凭据(组织凭据:`connectors.manage`;个人凭据:`connectors.use`,只写发起人自己的那一条)。
463
473
  * 形状与归属不符 → `validation_failed`。审计只记类型与归属。
464
474
  */
465
- setCredential(orgId: string, connectorId: string, actorAccountId: string, ownership: "org" | "personal", value: unknown, actorTokenId?: string): Promise<void>;
475
+ setCredential(orgId: string, connectorId: string, actorAccountId: string, ownership: "org" | "personal", value: unknown, actorTokenId?: string, auditDetail?: Record<string, unknown>): Promise<void>;
466
476
  /** The org-locked static credential write of {@link setCredential}. */
467
477
  private setCredentialIn;
468
478
  /**
@@ -475,5 +485,5 @@ export declare class ConnectorsService {
475
485
  /** The org-locked client (and token) write of {@link rotateOAuthClient}. */
476
486
  private storeOAuthClient;
477
487
  /** 删除发起人自己的个人凭据(`connectors.use`);本来就没有也成功。 */
478
- clearMyCredential(orgId: string, connectorId: string, actorAccountId: string, actorTokenId?: string): Promise<void>;
488
+ clearMyCredential(orgId: string, connectorId: string, actorAccountId: string, actorTokenId?: string, auditDetail?: Record<string, unknown>): Promise<void>;
479
489
  }
@@ -356,7 +356,7 @@ let ConnectorsService = class ConnectorsService {
356
356
  * OAuth(A16,要求 `http.publicUrl`):授权码连接器不做首次 listTools(首个成员连接后刷新),只存客户端;
357
357
  * 客户端凭据连接器用安装时取到的组织 token listTools,存客户端与 token。
358
358
  */
359
- async create(orgId, actorAccountId, input, actorTokenId) {
359
+ async create(orgId, actorAccountId, input, actorTokenId, auditDetail) {
360
360
  // 自建被禁止时先拒绝(事务里再复核一次):不该为此触发外连
361
361
  if (!input.template)
362
362
  await assertCustomAllowed(this.db, "customConnectors");
@@ -390,7 +390,7 @@ let ConnectorsService = class ConnectorsService {
390
390
  const guideAck = tpl?.templateId !== undefined
391
391
  ? await this.guides.templateAck(tpl.itemId, tpl.templateId)
392
392
  : null;
393
- return this.createIn(orgId, actorAccountId, input, actorTokenId, {
393
+ return this.createIn(orgId, actorAccountId, input, actorTokenId, auditDetail, {
394
394
  id,
395
395
  slug,
396
396
  endpoint,
@@ -402,7 +402,7 @@ let ConnectorsService = class ConnectorsService {
402
402
  });
403
403
  }
404
404
  /** The org-locked, re-checked insert of {@link create} (the outbound checks ran before). */
405
- async createIn(orgId, actorAccountId, input, actorTokenId, c) {
405
+ async createIn(orgId, actorAccountId, input, actorTokenId, auditDetail, c) {
406
406
  const { id, endpoint, owner, secret, oauth } = c;
407
407
  const auth = input.auth;
408
408
  const t = this.db;
@@ -486,6 +486,7 @@ let ConnectorsService = class ConnectorsService {
486
486
  action: "connector.created",
487
487
  target: id,
488
488
  detail: {
489
+ ...auditDetail,
489
490
  slug,
490
491
  connector: input.connector,
491
492
  auth: { type: auth.type, ...(auth.type !== "none" && { ownership: auth.ownership }) },
@@ -898,14 +899,26 @@ let ConnectorsService = class ConnectorsService {
898
899
  * connector without a template guide, or whose item the org's catalog does not show -> 404
899
900
  * `catalog.guide_not_found`.
900
901
  */
901
- async ackGuide(org, connectorId, hash, actorAccountId, actorTokenId) {
902
- const { orgId } = org;
902
+ async ackGuide(org, connectorId, hash, actorAccountId, actorTokenId, auditDetail) {
903
+ const ack = await this.currentGuide(org, connectorId);
904
+ if (ack.hash !== hash) {
905
+ throw new ApiError("connector.guide_changed", "The connector template's setup guide changed since it was shown; review the new guide first");
906
+ }
907
+ return this.ackIn(org.orgId, connectorId, ack, actorAccountId, actorTokenId, auditDetail);
908
+ }
909
+ /**
910
+ * The setup guide a connector made from a template would be acknowledged with now (the
911
+ * template's guide in its item's latest version, with its admin drift hash). An unknown
912
+ * connector -> 404 `connector.not_found`; one without a template guide, or whose item the org's
913
+ * catalog does not show -> 404 `catalog.guide_not_found`.
914
+ */
915
+ async currentGuide(org, connectorId) {
903
916
  const r = await this.db
904
917
  .selectFrom("connectors as c")
905
918
  .leftJoin("platform_connector_templates as t", "t.id", "c.platform_template_id")
906
919
  .select(["c.id", "t.catalog_item_id", "t.template_id"])
907
920
  .where("c.id", "=", connectorId)
908
- .where("c.org_id", "=", orgId)
921
+ .where("c.org_id", "=", org.orgId)
909
922
  .where("c.deleted_at", "is", null)
910
923
  .executeTakeFirst();
911
924
  if (!r)
@@ -917,13 +930,10 @@ let ConnectorsService = class ConnectorsService {
917
930
  if (ack === null) {
918
931
  throw new ApiError("catalog.guide_not_found", "The connector has no template setup guide");
919
932
  }
920
- if (ack.hash !== hash) {
921
- throw new ApiError("connector.guide_changed", "The connector template's setup guide changed since it was shown; review the new guide first");
922
- }
923
- return this.ackIn(orgId, connectorId, ack, actorAccountId, actorTokenId);
933
+ return ack;
924
934
  }
925
935
  /** The row and audit of {@link ackGuide}, in one transaction under the org lock. */
926
- async ackIn(orgId, connectorId, ack, actorAccountId, actorTokenId) {
936
+ async ackIn(orgId, connectorId, ack, actorAccountId, actorTokenId, auditDetail) {
927
937
  const t = this.db;
928
938
  await this.orgLock.lockAndAuthorize(orgId, actorAccountId, "connectors.manage");
929
939
  const updated = await t
@@ -942,7 +952,7 @@ let ConnectorsService = class ConnectorsService {
942
952
  orgId,
943
953
  action: "connector.guide_confirmed",
944
954
  target: connectorId,
945
- detail: { guideId: ack.guideId, version: ack.version },
955
+ detail: { ...auditDetail, guideId: ack.guideId, version: ack.version },
946
956
  });
947
957
  return this.detail(t, orgId, connectorId, actorAccountId);
948
958
  }
@@ -962,7 +972,7 @@ let ConnectorsService = class ConnectorsService {
962
972
  return this.detail(this.db, orgId, connectorId, viewerAccountId);
963
973
  }
964
974
  /** 改名、启停连接器、工具启停与默认策略、批量把无注解工具改为 allow(`connectors.manage`)。 */
965
- async update(orgId, connectorId, actorAccountId, patch, actorTokenId) {
975
+ async update(orgId, connectorId, actorAccountId, patch, actorTokenId, auditDetail) {
966
976
  const t = this.db;
967
977
  await this.orgLock.lockAndAuthorize(orgId, actorAccountId, "connectors.manage");
968
978
  const app = await this.row(t, orgId, connectorId, true);
@@ -1091,6 +1101,7 @@ let ConnectorsService = class ConnectorsService {
1091
1101
  action: "connector.updated",
1092
1102
  target: connectorId,
1093
1103
  detail: {
1104
+ ...auditDetail,
1094
1105
  ...(patch.name !== undefined && { name: { from: app.name, to: patch.name } }),
1095
1106
  ...(patch.status !== undefined && { status: { from: app.status, to: patch.status } }),
1096
1107
  ...(gitChanged && { useForGit: { from: app.use_for_git, to: patch.useForGit } }),
@@ -1416,19 +1427,19 @@ let ConnectorsService = class ConnectorsService {
1416
1427
  * 写凭据(组织凭据:`connectors.manage`;个人凭据:`connectors.use`,只写发起人自己的那一条)。
1417
1428
  * 形状与归属不符 → `validation_failed`。审计只记类型与归属。
1418
1429
  */
1419
- async setCredential(orgId, connectorId, actorAccountId, ownership, value, actorTokenId) {
1430
+ async setCredential(orgId, connectorId, actorAccountId, ownership, value, actorTokenId, auditDetail) {
1420
1431
  if (ownership === "org") {
1421
1432
  const app = await this.row(this.db, orgId, connectorId);
1422
1433
  const auth = app.auth;
1423
1434
  if (isOAuth(auth)) {
1424
- await this.rotateOAuthClient(orgId, connectorId, actorAccountId, auth, value, actorTokenId);
1435
+ await this.rotateOAuthClient(orgId, connectorId, actorAccountId, auth, value, actorTokenId, auditDetail);
1425
1436
  return;
1426
1437
  }
1427
1438
  }
1428
- await this.setCredentialIn(orgId, connectorId, actorAccountId, ownership, value, actorTokenId);
1439
+ await this.setCredentialIn(orgId, connectorId, actorAccountId, ownership, value, actorTokenId, auditDetail);
1429
1440
  }
1430
1441
  /** The org-locked static credential write of {@link setCredential}. */
1431
- async setCredentialIn(orgId, connectorId, actorAccountId, ownership, value, actorTokenId) {
1442
+ async setCredentialIn(orgId, connectorId, actorAccountId, ownership, value, actorTokenId, auditDetail) {
1432
1443
  const t = this.db;
1433
1444
  await this.orgLock.lockAndAuthorize(orgId, actorAccountId, ownership === "org" ? "connectors.manage" : "connectors.use");
1434
1445
  const app = await this.row(t, orgId, connectorId);
@@ -1442,7 +1453,7 @@ let ConnectorsService = class ConnectorsService {
1442
1453
  orgId,
1443
1454
  action: "connector.credential.set",
1444
1455
  target: connectorId,
1445
- detail: { type: auth.type, ownership },
1456
+ detail: { ...auditDetail, type: auth.type, ownership },
1446
1457
  });
1447
1458
  }
1448
1459
  /**
@@ -1451,7 +1462,7 @@ let ConnectorsService = class ConnectorsService {
1451
1462
  * 新 token 替换缓存的组织 token;授权码连接器只限手填 client,只替换客户端(成员的 token 保留,之后刷新若得到
1452
1463
  * invalid_client 会作废)。审计只记类型与归属。
1453
1464
  */
1454
- async rotateOAuthClient(orgId, connectorId, actorAccountId, auth, value, actorTokenId) {
1465
+ async rotateOAuthClient(orgId, connectorId, actorAccountId, auth, value, actorTokenId, auditDetail) {
1455
1466
  if (auth.type === "oauth_code" && auth.client !== "manual") {
1456
1467
  throw fail("auth.client", "The OAuth client of this connector was registered automatically and cannot be replaced");
1457
1468
  }
@@ -1480,10 +1491,10 @@ let ConnectorsService = class ConnectorsService {
1480
1491
  throw connectFailed(e);
1481
1492
  }
1482
1493
  }
1483
- await this.storeOAuthClient(orgId, connectorId, actorAccountId, auth, client, tokens, actorTokenId);
1494
+ await this.storeOAuthClient(orgId, connectorId, actorAccountId, auth, client, tokens, actorTokenId, auditDetail);
1484
1495
  }
1485
1496
  /** The org-locked client (and token) write of {@link rotateOAuthClient}. */
1486
- async storeOAuthClient(orgId, connectorId, actorAccountId, auth, client, tokens, actorTokenId) {
1497
+ async storeOAuthClient(orgId, connectorId, actorAccountId, auth, client, tokens, actorTokenId, auditDetail) {
1487
1498
  const t = this.db;
1488
1499
  await this.orgLock.lockAndAuthorize(orgId, actorAccountId, "connectors.manage");
1489
1500
  await this.row(t, orgId, connectorId, true);
@@ -1496,11 +1507,11 @@ let ConnectorsService = class ConnectorsService {
1496
1507
  orgId,
1497
1508
  action: "connector.credential.set",
1498
1509
  target: connectorId,
1499
- detail: { type: auth.type, ownership: "org" },
1510
+ detail: { ...auditDetail, type: auth.type, ownership: "org" },
1500
1511
  });
1501
1512
  }
1502
1513
  /** 删除发起人自己的个人凭据(`connectors.use`);本来就没有也成功。 */
1503
- async clearMyCredential(orgId, connectorId, actorAccountId, actorTokenId) {
1514
+ async clearMyCredential(orgId, connectorId, actorAccountId, actorTokenId, auditDetail) {
1504
1515
  const t = this.db;
1505
1516
  await this.orgLock.lockAndAuthorize(orgId, actorAccountId, "connectors.use");
1506
1517
  const app = await this.row(t, orgId, connectorId);
@@ -1511,7 +1522,11 @@ let ConnectorsService = class ConnectorsService {
1511
1522
  orgId,
1512
1523
  action: "connector.credential.cleared",
1513
1524
  target: connectorId,
1514
- detail: { type: app.auth.type, ownership: "personal" },
1525
+ detail: {
1526
+ ...auditDetail,
1527
+ type: app.auth.type,
1528
+ ownership: "personal",
1529
+ },
1515
1530
  });
1516
1531
  }
1517
1532
  };
@@ -1,12 +1,10 @@
1
1
  import type { FastifyReply, FastifyRequest } from "fastify";
2
- import { z } from "zod";
2
+ import type { z } from "zod";
3
3
  import { type Principal } from "../../identity/principal.js";
4
4
  import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
5
5
  import { type OrgContext } from "../../orgs/org.guard.js";
6
6
  import { OAuthFlow } from "./flow.js";
7
- declare const ConnectBody: z.ZodObject<{
8
- returnTo: z.ZodOptional<z.ZodString>;
9
- }, z.core.$strict>;
7
+ import { OAuthConnectBodySchema } from "./oauth.schemas.js";
10
8
  /**
11
9
  * 发起 OAuth 连接(`POST /orgs/:orgId/connectors/:connectorId/connect`,`connectors.use`,仅用户主体):返回授权 URL,并写浏览器绑定
12
10
  * Cookie `cap_oauth`(HttpOnly、SameSite=Lax——授权服务器回跳是跨站顶级 GET 导航、Lax 会带上;Path 只到回调)。
@@ -15,7 +13,7 @@ export declare class OAuthConnectController {
15
13
  private readonly flow;
16
14
  private readonly config;
17
15
  constructor(flow: OAuthFlow, config: KernelConfigService);
18
- connect(principal: Principal, org: OrgContext, connectorId: string, body: z.infer<typeof ConnectBody>, req: FastifyRequest, reply: FastifyReply): Promise<{
16
+ connect(principal: Principal, org: OrgContext, connectorId: string, body: z.infer<typeof OAuthConnectBodySchema>, req: FastifyRequest, reply: FastifyReply): Promise<{
19
17
  authorizationUrl: string;
20
18
  }>;
21
19
  }
@@ -28,4 +26,3 @@ export declare class OAuthCallbackController {
28
26
  constructor(flow: OAuthFlow);
29
27
  callback(q: Record<string, unknown>, req: FastifyRequest, reply: FastifyReply): Promise<void>;
30
28
  }
31
- export {};