@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.
- package/dist/admin/extensions.controller.d.ts +2 -10
- package/dist/admin/extensions.controller.js +2 -24
- package/dist/admin/extensions.schemas.d.ts +21 -0
- package/dist/admin/extensions.schemas.js +37 -0
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.controller.d.ts +0 -5
- package/dist/catalog/org-catalog.controller.js +3 -17
- package/dist/catalog/org-catalog.schemas.d.ts +43 -0
- package/dist/catalog/org-catalog.schemas.js +43 -2
- package/dist/catalog/org-extension-switch.d.ts +3 -1
- package/dist/catalog/org-extension-switch.js +12 -5
- package/dist/catalog/org-extension.controller.d.ts +2 -21
- package/dist/catalog/org-extension.controller.js +1 -38
- package/dist/catalog/org-extension.schemas.d.ts +31 -0
- package/dist/catalog/org-extension.schemas.js +65 -0
- package/dist/catalog/plugin-install.d.ts +2 -0
- package/dist/catalog/plugin-install.js +3 -3
- package/dist/channels/actions.js +2 -0
- package/dist/channels/cards.d.ts +8 -0
- package/dist/channels/cards.js +18 -0
- package/dist/channels/channels.schemas.d.ts +3 -0
- package/dist/channels/channels.schemas.js +8 -0
- package/dist/channels/connections.service.d.ts +17 -2
- package/dist/channels/connections.service.js +30 -5
- package/dist/channels/outbound.js +25 -1
- package/dist/channels/phrases.d.ts +10 -0
- package/dist/channels/phrases.js +10 -0
- package/dist/conversations/conversations.module.js +4 -0
- package/dist/conversations/events.d.ts +35 -0
- package/dist/conversations/events.js +29 -0
- package/dist/conversations/leak-check.d.ts +26 -0
- package/dist/conversations/leak-check.js +69 -0
- package/dist/ctx/secrets.d.ts +13 -1
- package/dist/ctx/secrets.js +19 -1
- package/dist/db/kernel-schema.d.ts +34 -0
- package/dist/devices/working-root.d.ts +2 -3
- package/dist/errors.d.ts +19 -0
- package/dist/errors.js +19 -0
- package/dist/extensions/deployment-config.d.ts +6 -2
- package/dist/extensions/deployment-config.js +35 -23
- package/dist/extensions/org-config.d.ts +2 -0
- package/dist/extensions/org-config.js +1 -0
- package/dist/extensions/org-overrides.d.ts +2 -0
- package/dist/extensions/org-overrides.js +3 -2
- package/dist/http/api.module.js +6 -0
- package/dist/identity/initial-passwords.job.d.ts +3 -2
- package/dist/identity/initial-passwords.job.js +11 -5
- package/dist/orgs/invitations.controller.d.ts +3 -11
- package/dist/orgs/invitations.controller.js +9 -10
- package/dist/orgs/invitations.service.d.ts +12 -2
- package/dist/orgs/invitations.service.js +14 -7
- package/dist/orgs/members.service.d.ts +12 -2
- package/dist/orgs/members.service.js +10 -8
- package/dist/orgs/orgs.controller.d.ts +4 -12
- package/dist/orgs/orgs.controller.js +10 -10
- package/dist/orgs/orgs.schemas.d.ts +26 -0
- package/dist/orgs/orgs.schemas.js +22 -0
- package/dist/platform/connector-person-fields.d.ts +67 -0
- package/dist/platform/connector-person-fields.js +129 -0
- package/dist/platform/exclusions.js +6 -141
- package/dist/platform/method.js +1 -0
- package/dist/platform/operation.d.ts +61 -2
- package/dist/platform/operation.js +4 -4
- package/dist/platform/ops/accounts.ops.js +1 -0
- package/dist/platform/ops/channels.ops.d.ts +10 -3
- package/dist/platform/ops/channels.ops.js +223 -5
- package/dist/platform/ops/connectors.ops.d.ts +22 -4
- package/dist/platform/ops/connectors.ops.js +664 -13
- package/dist/platform/ops/extensions-admin.ops.d.ts +15 -2
- package/dist/platform/ops/extensions-admin.ops.js +153 -5
- package/dist/platform/ops/extensions.ops.d.ts +19 -5
- package/dist/platform/ops/extensions.ops.js +285 -10
- package/dist/platform/ops/org-plugins.ops.d.ts +15 -2
- package/dist/platform/ops/org-plugins.ops.js +323 -4
- package/dist/platform/ops/orgs.ops.d.ts +40 -3
- package/dist/platform/ops/orgs.ops.js +293 -12
- package/dist/platform/ops/person-inputs.d.ts +65 -0
- package/dist/platform/ops/person-inputs.js +129 -0
- package/dist/platform/ops/plugins.ops.d.ts +3 -1
- package/dist/platform/ops/plugins.ops.js +33 -20
- package/dist/platform/parity.d.ts +7 -2
- package/dist/platform/parity.js +75 -13
- package/dist/platform/person-fields.d.ts +119 -0
- package/dist/platform/person-fields.js +403 -0
- package/dist/platform/platform.module.d.ts +4 -3
- package/dist/platform/platform.module.js +8 -5
- package/dist/platform/route-schemas.js +2 -0
- package/dist/platform/sealed-inputs.d.ts +44 -0
- package/dist/platform/sealed-inputs.js +116 -0
- package/dist/platform/sealed-reveals.controller.d.ts +20 -0
- package/dist/platform/sealed-reveals.controller.js +48 -0
- package/dist/platform/sealed-reveals.d.ts +52 -0
- package/dist/platform/sealed-reveals.js +153 -0
- package/dist/runtime/project/knowledge.js +24 -19
- package/dist/runtime/waits.js +8 -2
- package/dist/sandbox/permission-facts.d.ts +5 -1
- package/dist/sandbox/permission-facts.js +8 -2
- package/dist/setup/setup-guides.service.d.ts +5 -0
- package/dist/setup/setup-guides.service.js +2 -1
- package/dist/tools/approvals.controller.d.ts +1 -0
- package/dist/tools/approvals.controller.js +19 -0
- package/dist/tools/approvals.service.d.ts +50 -1
- package/dist/tools/approvals.service.js +118 -10
- package/dist/tools/builtins/builtin-tools.d.ts +3 -0
- package/dist/tools/builtins/builtin-tools.js +31 -9
- package/dist/tools/builtins/platform.d.ts +20 -0
- package/dist/tools/builtins/platform.js +214 -15
- package/dist/tools/connectors.controller.d.ts +6 -7
- package/dist/tools/connectors.controller.js +4 -44
- package/dist/tools/connectors.schemas.d.ts +170 -1
- package/dist/tools/connectors.schemas.js +82 -3
- package/dist/tools/connectors.service.d.ts +16 -6
- package/dist/tools/connectors.service.js +39 -24
- package/dist/tools/oauth/oauth.controller.d.ts +3 -6
- package/dist/tools/oauth/oauth.controller.js +3 -12
- package/dist/tools/oauth/oauth.schemas.d.ts +14 -0
- package/dist/tools/oauth/oauth.schemas.js +27 -0
- package/dist/tools/pipeline.d.ts +31 -2
- package/dist/tools/pipeline.js +89 -17
- package/dist/tools/policy.d.ts +4 -0
- package/dist/tools/policy.js +8 -0
- package/dist/tools/registry.d.ts +29 -0
- package/dist/tools/tools.module.js +3 -0
- package/package.json +3 -3
- package/src/migrations/0169_platform_sealed_inputs.sql +23 -0
- package/src/migrations/0170_platform_sealed_reveals.sql +27 -0
|
@@ -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
|
|
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
|
-
|
|
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: {
|
|
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
|
-
|
|
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
|
|
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 {};
|
|
@@ -8,23 +8,14 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
10
|
import { Controller, Get, HttpCode, Inject, Param, Post, Query, Req, Res } from "@nestjs/common";
|
|
11
|
-
import { z } from "zod";
|
|
12
11
|
import { CurrentPrincipal, Public, requireUser } from "../../identity/principal.js";
|
|
13
12
|
import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
|
|
14
13
|
import { createZodDto } from "../../infra/validation/create-zod-dto.js";
|
|
15
14
|
import { ZBody } from "../../infra/validation/zod-params.js";
|
|
16
15
|
import { CurrentOrg, OrgAction } from "../../orgs/org.guard.js";
|
|
17
|
-
import { browserBinding,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
returnTo: z
|
|
21
|
-
.string()
|
|
22
|
-
.max(500)
|
|
23
|
-
.refine(isSafeReturnPath, { message: "returnTo must be a relative path on this site" })
|
|
24
|
-
.optional(),
|
|
25
|
-
})
|
|
26
|
-
.strict();
|
|
27
|
-
class OAuthConnectBody extends createZodDto(ConnectBody, "OAuthConnectBody") {
|
|
16
|
+
import { browserBinding, OAUTH_BINDING_COOKIE, OAUTH_CALLBACK_PATH, OAUTH_STATE_TTL_SECONDS, OAuthFlow, } from "./flow.js";
|
|
17
|
+
import { OAuthConnectBodySchema } from "./oauth.schemas.js";
|
|
18
|
+
class OAuthConnectBody extends createZodDto(OAuthConnectBodySchema, "OAuthConnectBody") {
|
|
28
19
|
}
|
|
29
20
|
/** 查询参数只取单值字符串(重复参数 / 数组按缺失处理)。 */
|
|
30
21
|
const one = (v) => typeof v === "string" && v.length <= 4096 ? v : undefined;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { RouteSchemas } from "../../platform/route-schemas.js";
|
|
3
|
+
/**
|
|
4
|
+
* `POST …/connectors/:connectorId/connect`: where the browser returns after the authorization (a
|
|
5
|
+
* relative path on this site; default the connections page).
|
|
6
|
+
*/
|
|
7
|
+
export declare const OAuthConnectBodySchema: z.ZodObject<{
|
|
8
|
+
returnTo: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, z.core.$strict>;
|
|
10
|
+
/**
|
|
11
|
+
* The connect route's schemas for the Platform parity check (`connectors.connect` mirrors it; the
|
|
12
|
+
* OAuth callback stays an exclusion).
|
|
13
|
+
*/
|
|
14
|
+
export declare const OAUTH_ROUTES: readonly RouteSchemas[];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ConnectorPathParams } from "../connectors.schemas.js";
|
|
3
|
+
import { isSafeReturnPath } from "./flow-paths.js";
|
|
4
|
+
/**
|
|
5
|
+
* `POST …/connectors/:connectorId/connect`: where the browser returns after the authorization (a
|
|
6
|
+
* relative path on this site; default the connections page).
|
|
7
|
+
*/
|
|
8
|
+
export const OAuthConnectBodySchema = z
|
|
9
|
+
.object({
|
|
10
|
+
returnTo: z
|
|
11
|
+
.string()
|
|
12
|
+
.max(500)
|
|
13
|
+
.refine(isSafeReturnPath, { message: "returnTo must be a relative path on this site" })
|
|
14
|
+
.optional(),
|
|
15
|
+
})
|
|
16
|
+
.strict();
|
|
17
|
+
/**
|
|
18
|
+
* The connect route's schemas for the Platform parity check (`connectors.connect` mirrors it; the
|
|
19
|
+
* OAuth callback stays an exclusion).
|
|
20
|
+
*/
|
|
21
|
+
export const OAUTH_ROUTES = [
|
|
22
|
+
{
|
|
23
|
+
route: "POST /api/v1/orgs/:orgId/connectors/:connectorId/connect",
|
|
24
|
+
params: ConnectorPathParams,
|
|
25
|
+
body: OAuthConnectBodySchema,
|
|
26
|
+
},
|
|
27
|
+
];
|
package/dist/tools/pipeline.d.ts
CHANGED
|
@@ -44,6 +44,13 @@ export declare const approvalDeniedText: (reason: string | null) => string;
|
|
|
44
44
|
export declare const approvalExpiredText: (hours: number) => string;
|
|
45
45
|
/** 等待审批期间 run 被中止。 */
|
|
46
46
|
export declare const APPROVAL_CANCELLED_TEXT = "The run was stopped while waiting for approval.";
|
|
47
|
+
/** A person field refused on the approval card as leaked, for a call that then did not run. */
|
|
48
|
+
export declare const leakedOnCardText: (path: string) => string;
|
|
49
|
+
/**
|
|
50
|
+
* A call that ended without running: its text, then the leaked-on-card line per person field the
|
|
51
|
+
* approval card refused as leaked (`detail.leakedFields`), so the agent has the key rotated.
|
|
52
|
+
*/
|
|
53
|
+
export declare const withLeakedOnCard: (text: string, leakedFields: readonly string[] | undefined) => string;
|
|
47
54
|
/** What the review held: a shell command, a file write, or a file read outside the scope. */
|
|
48
55
|
export type ReviewKind = "command" | "write" | "read";
|
|
49
56
|
/**
|
|
@@ -78,6 +85,23 @@ export declare const INPUT_SKIPPED_TEXT = "The user did not provide the requeste
|
|
|
78
85
|
export declare const TOO_MANY_INPUT_REQUESTS_TEXT = "Tool requested user input too many times.";
|
|
79
86
|
/** run 已被中止 / 到达截止时间,调用尚未开始执行。 */
|
|
80
87
|
export declare const RUN_STOPPED_TEXT = "The run was stopped before this tool call was executed.";
|
|
88
|
+
/**
|
|
89
|
+
* A call with person fields in an unattended run (ruling R6): no person is there to type the
|
|
90
|
+
* values on the card.
|
|
91
|
+
*/
|
|
92
|
+
export declare const PERSON_FIELDS_UNATTENDED_TEXT = "This write needs the person to enter values on the web; it cannot run unattended.";
|
|
93
|
+
/**
|
|
94
|
+
* A call with person fields whose ask would go to a role instead of the person (ruling R5): only the
|
|
95
|
+
* person the run works for may type the values, and they lack the role.
|
|
96
|
+
*/
|
|
97
|
+
export declare const PERSON_FIELDS_ROLE_TEXT = "This write needs the person you work for to enter values; they lack the role. Ask an admin to do it on the web.";
|
|
98
|
+
/**
|
|
99
|
+
* A call only the person may confirm (`CallPolicy.personOnly`: its result is shown once to the
|
|
100
|
+
* approver) in an unattended run: nobody is there to approve and read it.
|
|
101
|
+
*/
|
|
102
|
+
export declare const PERSON_ONLY_UNATTENDED_TEXT = "This write shows its result once, on the web, to the person who approves it; it cannot run unattended.";
|
|
103
|
+
/** A call only the person may confirm whose ask would go to a role instead of the person. */
|
|
104
|
+
export declare const PERSON_ONLY_ROLE_TEXT = "This write shows its result once to the person you work for, who must approve it; they lack the role. Ask an admin to do it on the web.";
|
|
81
105
|
/** 调用执行中 run 被中止 / 到达截止时间。 */
|
|
82
106
|
export declare const RUN_STOPPED_DURING_TEXT = "The run was stopped while this tool call was running; its outcome is unknown. Verify before retrying.";
|
|
83
107
|
/**
|
|
@@ -458,7 +482,10 @@ export declare class ToolPipeline {
|
|
|
458
482
|
* 或找不到 model_call 时返回 null(不做加载检查)。已加载集合由此从日志得出,不放进程内存。
|
|
459
483
|
*/
|
|
460
484
|
private sentTools;
|
|
461
|
-
/**
|
|
485
|
+
/**
|
|
486
|
+
* A decided approval other than approved → the model's text; still pending → null (wait). A
|
|
487
|
+
* person field refused on the card as leaked is named, so the agent has the key rotated.
|
|
488
|
+
*/
|
|
462
489
|
private refusalText;
|
|
463
490
|
/**
|
|
464
491
|
* A handler returned `input_required`: past the round limit, an invalid form
|
|
@@ -476,7 +503,9 @@ export declare class ToolPipeline {
|
|
|
476
503
|
against?: string | undefined;
|
|
477
504
|
escalation?: "available" | "escalated" | undefined;
|
|
478
505
|
escalationRefusal?: string | undefined;
|
|
479
|
-
}
|
|
506
|
+
},
|
|
507
|
+
/** The approved approval of this call, matching its definition and input (builtins only). */
|
|
508
|
+
approvalId?: string): Promise<ExecOutcome>;
|
|
480
509
|
private executeConnector;
|
|
481
510
|
/** 抛出的错误 → 给模型的结果:ToolError 的消息原样(插件约定为英文、可操作),其他只给错误类名。 */
|
|
482
511
|
private thrown;
|