@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
|
@@ -19,12 +19,15 @@ import { AccountsService } from "../../identity/accounts.js";
|
|
|
19
19
|
import { DEPLOYMENT_SETTINGS_PATCH, SettingsService } from "../../identity/settings.js";
|
|
20
20
|
import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
|
|
21
21
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
22
|
+
import { InvitationsService } from "../../orgs/invitations.service.js";
|
|
22
23
|
import { MembersService } from "../../orgs/members.service.js";
|
|
23
24
|
import { OrgNetworkAllowances } from "../../orgs/network-allowances.service.js";
|
|
24
|
-
import { networkAllowanceView, OrgUpdateBody } from "../../orgs/orgs.schemas.js";
|
|
25
|
+
import { InvitationCreateBody, InvitationIdParams, MemberParams, MemberRoleBody, networkAllowanceView, OrgUpdateBody, } from "../../orgs/orgs.schemas.js";
|
|
25
26
|
import { OrgsService } from "../../orgs/orgs.service.js";
|
|
27
|
+
import { roleAtLeast } from "../../orgs/roles.js";
|
|
26
28
|
import { defineOperation } from "../operation.js";
|
|
27
29
|
import { PlatformOperations } from "../registry.js";
|
|
30
|
+
import { SEALED_REVEAL_TTL_MS, SealedReveals } from "../sealed-reveals.js";
|
|
28
31
|
import { precheckBy, viaAgent } from "./errors.js";
|
|
29
32
|
import { Cursor, pageOf, startOf } from "./paging.js";
|
|
30
33
|
import { roleOf } from "./role.js";
|
|
@@ -45,16 +48,80 @@ async function limitsOf(settings, orgId) {
|
|
|
45
48
|
subagents: s.subagentLimitOverrides[orgId] ?? null,
|
|
46
49
|
};
|
|
47
50
|
}
|
|
51
|
+
/** The role names a card summary uses. */
|
|
52
|
+
const ROLE_WORDS = {
|
|
53
|
+
owner: { zh: "所有者", en: "owner" },
|
|
54
|
+
admin: { zh: "管理员", en: "admin" },
|
|
55
|
+
member: { zh: "成员", en: "member" },
|
|
56
|
+
guest: { zh: "访客", en: "guest" },
|
|
57
|
+
};
|
|
58
|
+
/** What `orgs.invite` returns in place of the token (model-visible English). */
|
|
59
|
+
export const INVITATION_LINK_NOTE = `The invitation link is shown once, on the web, to the person who approved this call (on the approval card); they share it with the invitee. It is not shown to you. If it is not read within ${SEALED_REVEAL_TTL_MS / 3_600_000} hours it is lost: revoke the invitation (orgs.revoke-invitation) and invite again.`;
|
|
60
|
+
/**
|
|
61
|
+
* Why a member operation through the tool is never offered (spec §7.2, maintainer decision Q2):
|
|
62
|
+
* the actor's own membership (`member.self`), an owner or granting owner
|
|
63
|
+
* (`member.owner_untouchable`), or a role above the actor's own (`member.role_above_actor`). Null:
|
|
64
|
+
* allowed here; the service's own checks still run. A target that is no member is left to the
|
|
65
|
+
* service (`member.not_found`).
|
|
66
|
+
*/
|
|
67
|
+
export function memberChangeRefusal(actor, target, role) {
|
|
68
|
+
if (target.id === actor.id) {
|
|
69
|
+
return {
|
|
70
|
+
code: "member.self",
|
|
71
|
+
message: "The Platform tool never changes or removes your own membership",
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (target.role === "owner" || role === "owner") {
|
|
75
|
+
return {
|
|
76
|
+
code: "member.owner_untouchable",
|
|
77
|
+
message: "The Platform tool never touches an owner or makes anyone an owner",
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return role === undefined ? null : roleAboveActor(actor.role, role);
|
|
81
|
+
}
|
|
82
|
+
/** `member.role_above_actor` when `role` is above the actor's own (or the actor has none). */
|
|
83
|
+
export function roleAboveActor(actorRole, role) {
|
|
84
|
+
return actorRole !== null && roleAtLeast(actorRole, role)
|
|
85
|
+
? null
|
|
86
|
+
: {
|
|
87
|
+
code: "member.role_above_actor",
|
|
88
|
+
message: `The Platform tool never gives a role above your own (${actorRole ?? "none"})`,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/** Throws a refusal as the {@link ApiError} of its code. */
|
|
92
|
+
function refuse(r) {
|
|
93
|
+
if (r !== null)
|
|
94
|
+
throw new ApiError(r.code, r.message);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The member service's guard (`MemberWriteOptions.guard`): {@link memberChangeRefusal} on the roles
|
|
98
|
+
* read under the org row lock, so a role that changed after the precheck is still refused.
|
|
99
|
+
*/
|
|
100
|
+
const memberGuard = (actorId, targetId, role) => (actorRole, targetRole) => refuse(memberChangeRefusal({ id: actorId, role: actorRole }, { id: targetId, role: targetRole }, role));
|
|
101
|
+
/** The invitation as the tool shows it: never a token (the list has none; create's is sealed). */
|
|
102
|
+
const invitationView = (i) => ({
|
|
103
|
+
id: i.id,
|
|
104
|
+
role: i.role,
|
|
105
|
+
...(i.status !== undefined && { status: i.status }),
|
|
106
|
+
createdBy: i.createdBy,
|
|
107
|
+
createdAt: i.createdAt,
|
|
108
|
+
expiresAt: i.expiresAt,
|
|
109
|
+
acceptedAt: i.acceptedAt,
|
|
110
|
+
revokedAt: i.revokedAt,
|
|
111
|
+
});
|
|
48
112
|
/**
|
|
49
113
|
* Org operations of the `Platform` tool (spec §14.2): the super admin's view of every org (list,
|
|
50
114
|
* get, the per-org limits) through their own private agent, and the conversation's org for its
|
|
51
|
-
* members (read, rename, member list, the org audit log for its admins)
|
|
52
|
-
*
|
|
115
|
+
* members (read, rename, member list, the org audit log for its admins), and member management for
|
|
116
|
+
* its admins (invite, revoke, role change, remove; platform web parity spec §7.2: never self, never
|
|
117
|
+
* an owner, never above the actor). Creating, deleting and transferring an org stay on the web.
|
|
53
118
|
*/
|
|
54
119
|
let OrgsOperations = class OrgsOperations {
|
|
55
120
|
registry;
|
|
56
121
|
orgs;
|
|
57
122
|
members;
|
|
123
|
+
invitations;
|
|
124
|
+
reveals;
|
|
58
125
|
settings;
|
|
59
126
|
accounts;
|
|
60
127
|
config;
|
|
@@ -62,10 +129,12 @@ let OrgsOperations = class OrgsOperations {
|
|
|
62
129
|
audit;
|
|
63
130
|
networkAdmin;
|
|
64
131
|
allowances;
|
|
65
|
-
constructor(registry, orgs, members, settings, accounts, config, kdb, audit, networkAdmin, allowances) {
|
|
132
|
+
constructor(registry, orgs, members, invitations, reveals, settings, accounts, config, kdb, audit, networkAdmin, allowances) {
|
|
66
133
|
this.registry = registry;
|
|
67
134
|
this.orgs = orgs;
|
|
68
135
|
this.members = members;
|
|
136
|
+
this.invitations = invitations;
|
|
137
|
+
this.reveals = reveals;
|
|
69
138
|
this.settings = settings;
|
|
70
139
|
this.accounts = accounts;
|
|
71
140
|
this.config = config;
|
|
@@ -87,6 +156,26 @@ let OrgsOperations = class OrgsOperations {
|
|
|
87
156
|
throw new ApiError("forbidden", "Your account no longer exists");
|
|
88
157
|
return a;
|
|
89
158
|
}
|
|
159
|
+
/** The precheck of a member operation: {@link memberChangeRefusal} on the roles read now. */
|
|
160
|
+
async memberCheck(ctx, targetId, role) {
|
|
161
|
+
const [actorRole, targetRole] = await Promise.all([
|
|
162
|
+
roleOf(this.kdb.db, ctx.orgId, ctx.actorAccountId),
|
|
163
|
+
roleOf(this.kdb.db, ctx.orgId, targetId),
|
|
164
|
+
]);
|
|
165
|
+
const refused = memberChangeRefusal({ id: ctx.actorAccountId, role: actorRole }, { id: targetId, role: targetRole }, role);
|
|
166
|
+
return refused === null ? { ok: true } : { ok: false, ...refused };
|
|
167
|
+
}
|
|
168
|
+
/** The precheck of `orgs.invite`, and its run's check: never a role above the actor's. */
|
|
169
|
+
async inviteRefusal(ctx, role) {
|
|
170
|
+
return roleAboveActor(await roleOf(this.kdb.db, ctx.orgId, ctx.actorAccountId), role);
|
|
171
|
+
}
|
|
172
|
+
/** The member's display name for a card; the id when unknown. */
|
|
173
|
+
async memberName(accountId) {
|
|
174
|
+
return orElse(async () => {
|
|
175
|
+
const a = await this.accounts.get(accountId);
|
|
176
|
+
return a === undefined || a === null ? accountId : named(a.displayName);
|
|
177
|
+
}, accountId);
|
|
178
|
+
}
|
|
90
179
|
/** The org's allowance `id` (for a card and the remove precheck); none → the remove's 404. */
|
|
91
180
|
async allowance(orgId, id) {
|
|
92
181
|
const a = (await this.networkAdmin.list(orgId)).find((x) => x.id === id);
|
|
@@ -395,7 +484,7 @@ let OrgsOperations = class OrgsOperations {
|
|
|
395
484
|
}),
|
|
396
485
|
defineOperation({
|
|
397
486
|
id: "orgs.members",
|
|
398
|
-
description: "List the members of this conversation's org, one compact row each: account id, display name, role, email and when they joined.
|
|
487
|
+
description: "List the members of this conversation's org, one compact row each: account id, display name, role, email and when they joined. Org admins change roles with orgs.set-member-role and remove members with orgs.remove-member. Pages by 50: pass the returned next as params.cursor.",
|
|
399
488
|
input: z.object({ cursor: Cursor.optional() }).strict(),
|
|
400
489
|
example: {},
|
|
401
490
|
authz: { orgAction: "org.members.read" },
|
|
@@ -411,6 +500,196 @@ let OrgsOperations = class OrgsOperations {
|
|
|
411
500
|
...(m.anonymous && { anonymous: true }),
|
|
412
501
|
})), startOf(input.cursor), PAGE),
|
|
413
502
|
}),
|
|
503
|
+
defineOperation({
|
|
504
|
+
id: "orgs.invitations",
|
|
505
|
+
description: "List the invitations of this conversation's org (org admins), oldest first: id, role, status (pending, accepted, expired or revoked), who created it and when, when it expires. Never the link: an invitation's link is shown only once, to the person who approved its creation.",
|
|
506
|
+
input: z.object({ cursor: Cursor.optional() }).strict(),
|
|
507
|
+
example: {},
|
|
508
|
+
authz: { orgAction: "org.invitations.manage" },
|
|
509
|
+
mirrors: ["GET /api/v1/orgs/:orgId/invitations"],
|
|
510
|
+
extras: ["cursor"],
|
|
511
|
+
confirm: "read",
|
|
512
|
+
run: async (input, ctx) => pageOf((await this.invitations.list(ctx.orgId)).map(invitationView), startOf(input.cursor), PAGE),
|
|
513
|
+
}),
|
|
514
|
+
defineOperation({
|
|
515
|
+
id: "orgs.invite",
|
|
516
|
+
description: "Invite a person into this conversation's org (org admins) with a role: admin, member or guest (never owner; never above your own role). expiresInHours is 1 to 720 (default 168). You never see the link: it is shown once, on the web, to the person who approves this call (on the approval card), who shares it with the invitee. If it is not read within 24 hours it is lost: revoke the invitation (orgs.revoke-invitation) and invite again.",
|
|
517
|
+
input: InvitationCreateBody.strict(),
|
|
518
|
+
example: { role: "member" },
|
|
519
|
+
authz: { orgAction: "org.invitations.manage" },
|
|
520
|
+
mirrors: ["POST /api/v1/orgs/:orgId/invitations"],
|
|
521
|
+
confirm: "org",
|
|
522
|
+
rememberable: false,
|
|
523
|
+
revealsToApprover: true,
|
|
524
|
+
errors: [
|
|
525
|
+
{
|
|
526
|
+
code: "member.role_above_actor",
|
|
527
|
+
next: "Invite with a role no higher than your own, or ask an owner to invite on the web.",
|
|
528
|
+
},
|
|
529
|
+
{
|
|
530
|
+
code: "invitation.create_needs_approval",
|
|
531
|
+
next: "Call it from a conversation where you approve the call yourself, or invite on the web (the org's Members page).",
|
|
532
|
+
},
|
|
533
|
+
{
|
|
534
|
+
code: "validation_failed",
|
|
535
|
+
next: "Pass role admin, member or guest and expiresInHours from 1 to 720.",
|
|
536
|
+
},
|
|
537
|
+
],
|
|
538
|
+
precheck: async (i, ctx) => {
|
|
539
|
+
const refused = await this.inviteRefusal(ctx, i.role);
|
|
540
|
+
return refused === null ? { ok: true } : { ok: false, ...refused };
|
|
541
|
+
},
|
|
542
|
+
summary: (i) => {
|
|
543
|
+
const h = i.expiresInHours;
|
|
544
|
+
return {
|
|
545
|
+
zh: `邀请一位${ROLE_WORDS[i.role].zh}加入本组织${h === undefined ? "" : `,${h} 小时后过期`};批准后邀请链接仅向你显示一次`,
|
|
546
|
+
en: `Invite a new ${ROLE_WORDS[i.role].en} into this org${h === undefined ? "" : `, expiring in ${h} hours`}; the invitation link is shown once to you after approval`,
|
|
547
|
+
};
|
|
548
|
+
},
|
|
549
|
+
run: async (input, ctx) => {
|
|
550
|
+
if (ctx.callId === undefined || ctx.runId === null) {
|
|
551
|
+
// the link reaches the approver through the approved call; without one it could never
|
|
552
|
+
// be shown, so nothing is created
|
|
553
|
+
throw new ApiError("invitation.create_needs_approval", "orgs.invite runs only as a Platform call you approve in a conversation");
|
|
554
|
+
}
|
|
555
|
+
// the service re-checks the role under the org row lock (`forbidden`)
|
|
556
|
+
refuse(await this.inviteRefusal(ctx, input.role));
|
|
557
|
+
const to = {
|
|
558
|
+
conversationId: ctx.conversationId,
|
|
559
|
+
runId: ctx.runId,
|
|
560
|
+
callId: ctx.callId,
|
|
561
|
+
recipientAccountId: ctx.actorAccountId,
|
|
562
|
+
};
|
|
563
|
+
const { invitation } = await this.invitations.create(ctx.orgId, input, ctx.actorAccountId, undefined, {
|
|
564
|
+
auditDetail: viaAgent("orgs.invite", ctx),
|
|
565
|
+
inTransaction: (inv, token) => this.reveals.sealIn(ctx.orgId, inv.id, token, to),
|
|
566
|
+
});
|
|
567
|
+
return { invitation: invitationView(invitation), link: INVITATION_LINK_NOTE };
|
|
568
|
+
},
|
|
569
|
+
}),
|
|
570
|
+
defineOperation({
|
|
571
|
+
id: "orgs.revoke-invitation",
|
|
572
|
+
description: "Revoke an invitation of this conversation's org (org admins) by its id (orgs.invitations): its link stops working at once. An accepted invitation cannot be revoked (remove the member instead); revoking one already revoked does nothing.",
|
|
573
|
+
input: z.object({ invitationId: InvitationIdParams.shape.id }).strict(),
|
|
574
|
+
example: { invitationId: "00000000-0000-4000-8000-000000000000" },
|
|
575
|
+
authz: { orgAction: "org.invitations.manage" },
|
|
576
|
+
mirrors: ["DELETE /api/v1/orgs/:orgId/invitations/:id"],
|
|
577
|
+
renames: { invitationId: "id" },
|
|
578
|
+
confirm: "org",
|
|
579
|
+
rememberable: false,
|
|
580
|
+
errors: [
|
|
581
|
+
{
|
|
582
|
+
code: "invitation.invalid",
|
|
583
|
+
next: "List the invitations with orgs.invitations and pass one of their ids.",
|
|
584
|
+
},
|
|
585
|
+
{
|
|
586
|
+
code: "invitation.used",
|
|
587
|
+
next: "The invitation was accepted; remove the member with orgs.remove-member if they should leave.",
|
|
588
|
+
},
|
|
589
|
+
],
|
|
590
|
+
summary: async (i, ctx) => {
|
|
591
|
+
const inv = await orElse(async () => (await this.invitations.list(ctx.orgId)).find((x) => x.id === i.invitationId), undefined);
|
|
592
|
+
const role = inv === undefined ? undefined : ROLE_WORDS[inv.role];
|
|
593
|
+
return {
|
|
594
|
+
zh: `撤销${role === undefined ? "" : `${role.zh}`}邀请 ${i.invitationId},它的链接将立即失效`,
|
|
595
|
+
en: `Revoke the ${role === undefined ? "" : `${role.en} `}invitation ${i.invitationId}; its link stops working at once`,
|
|
596
|
+
};
|
|
597
|
+
},
|
|
598
|
+
run: async (input, ctx) => {
|
|
599
|
+
await this.invitations.revoke(ctx.orgId, input.invitationId, ctx.actorAccountId, undefined, viaAgent("orgs.revoke-invitation", ctx));
|
|
600
|
+
return { id: input.invitationId, revoked: true };
|
|
601
|
+
},
|
|
602
|
+
}),
|
|
603
|
+
defineOperation({
|
|
604
|
+
id: "orgs.set-member-role",
|
|
605
|
+
description: "Change a member's role in this conversation's org (org admins): guest, member or admin, never above your own role. Never offered: changing your own role, changing an owner's role or making anyone an owner (an owner does that on the web).",
|
|
606
|
+
input: MemberParams.extend(MemberRoleBody.shape).strict(),
|
|
607
|
+
example: { accountId: "00000000-0000-4000-8000-000000000000", role: "member" },
|
|
608
|
+
authz: { orgAction: "org.members.manage" },
|
|
609
|
+
mirrors: ["PATCH /api/v1/orgs/:orgId/members/:accountId"],
|
|
610
|
+
confirm: "org",
|
|
611
|
+
rememberable: false,
|
|
612
|
+
errors: [
|
|
613
|
+
{
|
|
614
|
+
code: "member.role_above_actor",
|
|
615
|
+
next: "Choose a role no higher than your own, or ask an owner to change it on the web.",
|
|
616
|
+
},
|
|
617
|
+
{
|
|
618
|
+
code: "member.self",
|
|
619
|
+
next: "Your own membership is changed by you on the web, never through this tool.",
|
|
620
|
+
},
|
|
621
|
+
{
|
|
622
|
+
code: "member.owner_untouchable",
|
|
623
|
+
next: "Owners and ownership are changed by an owner on the web (the org's Members page), never through this tool.",
|
|
624
|
+
},
|
|
625
|
+
{
|
|
626
|
+
code: "member.not_found",
|
|
627
|
+
next: "List the members with orgs.members and pass one of their ids.",
|
|
628
|
+
},
|
|
629
|
+
{
|
|
630
|
+
code: "member.anonymous_guest",
|
|
631
|
+
next: "The anonymous guest has no role to change; switch the channel connection back to binding on the web if it is no longer wanted.",
|
|
632
|
+
},
|
|
633
|
+
],
|
|
634
|
+
precheck: (i, ctx) => this.memberCheck(ctx, i.accountId, i.role),
|
|
635
|
+
summary: async (i) => {
|
|
636
|
+
const name = await this.memberName(i.accountId);
|
|
637
|
+
return {
|
|
638
|
+
zh: `将成员「${name}」的角色改为${ROLE_WORDS[i.role].zh}`,
|
|
639
|
+
en: `Change the role of member "${name}" to ${ROLE_WORDS[i.role].en}`,
|
|
640
|
+
};
|
|
641
|
+
},
|
|
642
|
+
run: async (input, ctx) => {
|
|
643
|
+
await this.members.changeRole(ctx.orgId, input.accountId, input.role, ctx.actorAccountId, undefined, {
|
|
644
|
+
auditDetail: viaAgent("orgs.set-member-role", ctx),
|
|
645
|
+
guard: memberGuard(ctx.actorAccountId, input.accountId, input.role),
|
|
646
|
+
});
|
|
647
|
+
return { accountId: input.accountId, role: input.role };
|
|
648
|
+
},
|
|
649
|
+
}),
|
|
650
|
+
defineOperation({
|
|
651
|
+
id: "orgs.remove-member",
|
|
652
|
+
description: "Remove a member from this conversation's org (org admins): they lose access at once; every session and personal access token of the account is revoked, their runs in the org stop, their devices and file shares in the org are removed, and the org agents they own pass to an owner for reassignment. Never offered: removing yourself or an owner.",
|
|
653
|
+
input: MemberParams.strict(),
|
|
654
|
+
example: { accountId: "00000000-0000-4000-8000-000000000000" },
|
|
655
|
+
authz: { orgAction: "org.members.manage" },
|
|
656
|
+
mirrors: ["DELETE /api/v1/orgs/:orgId/members/:accountId"],
|
|
657
|
+
confirm: "org",
|
|
658
|
+
rememberable: false,
|
|
659
|
+
errors: [
|
|
660
|
+
{
|
|
661
|
+
code: "member.self",
|
|
662
|
+
next: "Your own membership is changed by you on the web, never through this tool.",
|
|
663
|
+
},
|
|
664
|
+
{
|
|
665
|
+
code: "member.owner_untouchable",
|
|
666
|
+
next: "Owners and ownership are changed by an owner on the web (the org's Members page), never through this tool.",
|
|
667
|
+
},
|
|
668
|
+
{
|
|
669
|
+
code: "member.not_found",
|
|
670
|
+
next: "List the members with orgs.members and pass one of their ids.",
|
|
671
|
+
},
|
|
672
|
+
{
|
|
673
|
+
code: "member.anonymous_guest",
|
|
674
|
+
next: "The anonymous guest cannot be removed; switch the channel connection back to binding on the web if anonymous access is no longer wanted.",
|
|
675
|
+
},
|
|
676
|
+
],
|
|
677
|
+
precheck: (i, ctx) => this.memberCheck(ctx, i.accountId),
|
|
678
|
+
summary: async (i) => {
|
|
679
|
+
const name = await this.memberName(i.accountId);
|
|
680
|
+
return {
|
|
681
|
+
zh: `将成员「${name}」移出本组织,其访问权限立即失效`,
|
|
682
|
+
en: `Remove member "${name}" from this org; their access ends at once`,
|
|
683
|
+
};
|
|
684
|
+
},
|
|
685
|
+
run: async (input, ctx) => {
|
|
686
|
+
await this.members.remove(ctx.orgId, input.accountId, ctx.actorAccountId, undefined, {
|
|
687
|
+
auditDetail: viaAgent("orgs.remove-member", ctx),
|
|
688
|
+
guard: memberGuard(ctx.actorAccountId, input.accountId),
|
|
689
|
+
});
|
|
690
|
+
return { accountId: input.accountId, removed: true };
|
|
691
|
+
},
|
|
692
|
+
}),
|
|
414
693
|
defineOperation({
|
|
415
694
|
id: "orgs.audit",
|
|
416
695
|
description: "The audit log of this conversation's org (org admins), newest first: members and invitations, settings, agents, connectors, skills, plugins and extensions in the org, channels, schedules. Each event has its id, time, actor (id, name, email; null for the kernel itself), viaToken (done with a personal access token), viaAgent (done through the Platform tool), action and target; never the event's details. action filters by an action name or its prefix (e.g. org.member.). limit is 1 to 100 (default 20); pages by keyset: pass the returned next as params.after (null: no more).",
|
|
@@ -429,12 +708,14 @@ OrgsOperations = __decorate([
|
|
|
429
708
|
__param(0, Inject(PlatformOperations)),
|
|
430
709
|
__param(1, Inject(OrgsService)),
|
|
431
710
|
__param(2, Inject(MembersService)),
|
|
432
|
-
__param(3, Inject(
|
|
433
|
-
__param(4, Inject(
|
|
434
|
-
__param(5, Inject(
|
|
435
|
-
__param(6, Inject(
|
|
436
|
-
__param(7, Inject(
|
|
437
|
-
__param(8, Inject(
|
|
438
|
-
__param(9, Inject(
|
|
711
|
+
__param(3, Inject(InvitationsService)),
|
|
712
|
+
__param(4, Inject(SealedReveals)),
|
|
713
|
+
__param(5, Inject(SettingsService)),
|
|
714
|
+
__param(6, Inject(AccountsService)),
|
|
715
|
+
__param(7, Inject(KernelConfigService)),
|
|
716
|
+
__param(8, Inject(KernelDb)),
|
|
717
|
+
__param(9, Inject(AuditLogService)),
|
|
718
|
+
__param(10, Inject(OrgNetworkAdmin)),
|
|
719
|
+
__param(11, Inject(OrgNetworkAllowances))
|
|
439
720
|
], OrgsOperations);
|
|
440
721
|
export { OrgsOperations };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { OperationContext } from "../operation.js";
|
|
2
|
+
/**
|
|
3
|
+
* Runs a write that may carry the person's card values (platform web parity spec §4.3): inside
|
|
4
|
+
* `ctx.personInputs.apply` when the approved call asked for person fields, so the sealed values
|
|
5
|
+
* are consumed in the write's own transaction, else directly with none. `write` gets the values
|
|
6
|
+
* by dot path and the audit detail: `viaAgent(operation)` plus `inputsProvided` (the entered
|
|
7
|
+
* paths, never the values) when the person entered any (spec §10).
|
|
8
|
+
*/
|
|
9
|
+
export declare function withPersonInputs<T>(operation: string, ctx: OperationContext, write: (entered: Readonly<Record<string, string>>, auditDetail: Record<string, unknown>) => Promise<T>): Promise<T>;
|
|
10
|
+
/**
|
|
11
|
+
* Ruling R11 (platform web parity plan): the one exception to "the write runs inside
|
|
12
|
+
* `personInputs.apply`". The catalog install runs `requires_new` steps that take the org row lock;
|
|
13
|
+
* inside `apply`, `connectors.create` would take that lock in the consuming transaction and the
|
|
14
|
+
* next step would wait on it for good. Such a write takes the values first and runs outside.
|
|
15
|
+
*
|
|
16
|
+
* The person's card values for a write that cannot run inside the consuming transaction: one made
|
|
17
|
+
* of several transactions of its own (`requires_new` steps under the org row lock, such as the
|
|
18
|
+
* catalog install), which would wait on a lock the consuming transaction holds. The values are
|
|
19
|
+
* consumed in a short transaction of their own and returned with the audit detail
|
|
20
|
+
* ({@link withPersonInputs}'s); the write then runs outside it. A write that fails after this
|
|
21
|
+
* leaves nothing to retry with: the call is made again, with a new card, like any failed call.
|
|
22
|
+
*/
|
|
23
|
+
export declare function takePersonInputs(operation: string, ctx: OperationContext): Promise<{
|
|
24
|
+
entered: Readonly<Record<string, string>>;
|
|
25
|
+
auditDetail: Record<string, unknown>;
|
|
26
|
+
}>;
|
|
27
|
+
/** What the model is told after a failed write consumed the person's values. */
|
|
28
|
+
export declare const VALUES_USED_UP_TEXT = "The values the person entered were used up: calling the operation again shows a new card where the person enters them again.";
|
|
29
|
+
/**
|
|
30
|
+
* The error of a write that failed after {@link takePersonInputs} consumed the values: the same
|
|
31
|
+
* error (an `ApiError` keeps its code and details, a `ToolError` its kind), its message saying the
|
|
32
|
+
* values are gone and the person enters them again on a new card. Any other error becomes a
|
|
33
|
+
* `ToolError` naming only its class (as the pipeline would), with the original as `cause`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function afterTaken(e: unknown, entered: Readonly<Record<string, string>>): unknown;
|
|
36
|
+
/**
|
|
37
|
+
* The values under `prefix` (`connectors.<templateId>.`), keyed by the rest of their path.
|
|
38
|
+
*/
|
|
39
|
+
export declare function enteredUnder(entered: Readonly<Record<string, string>>, prefix: string): Record<string, string>;
|
|
40
|
+
/**
|
|
41
|
+
* The `values` of a config route keyed by field dot path (deployment config, the org's copy): the
|
|
42
|
+
* model's non-secret values, the person's entered secrets, and `null` (clear) for each path in
|
|
43
|
+
* `clear`. A secret left out keeps its stored value, as on the web form.
|
|
44
|
+
*/
|
|
45
|
+
export declare function flatValues(values: Readonly<Record<string, unknown>>, entered: Readonly<Record<string, string>>, clear: readonly string[]): Record<string, unknown>;
|
|
46
|
+
/**
|
|
47
|
+
* The whole org config (`config` of `PUT /orgs/:orgId/extensions/:extension`, a nested object): the
|
|
48
|
+
* model's non-secret config with the person's entered secrets set at their dot paths and `null`
|
|
49
|
+
* (clear) at each path in `clear`. A secret left out keeps its stored value.
|
|
50
|
+
*/
|
|
51
|
+
export declare function nestedConfig(values: Readonly<Record<string, unknown>>, entered: Readonly<Record<string, string>>, clear: readonly string[]): Record<string, unknown>;
|
|
52
|
+
/**
|
|
53
|
+
* The card text of a config write: the non-secret values it sets, the secrets the person enters
|
|
54
|
+
* and the secrets it clears (paths only), e.g. `baseUrl="https://…"; the person enters apiKey`.
|
|
55
|
+
* The entered secrets are the plan's (`ctx.personAsk`: required secrets the call did not name
|
|
56
|
+
* included), else the call's `askPerson`.
|
|
57
|
+
*/
|
|
58
|
+
export declare function configChanges(i: {
|
|
59
|
+
values: Readonly<Record<string, unknown>>;
|
|
60
|
+
askPerson: readonly string[];
|
|
61
|
+
clearSecrets: readonly string[];
|
|
62
|
+
}, ctx: Pick<OperationContext, "personAsk">): {
|
|
63
|
+
zh: string;
|
|
64
|
+
en: string;
|
|
65
|
+
};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { ToolError } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { ApiError } from "../../errors.js";
|
|
3
|
+
import { setDeep } from "../../extensions/deployment-config-store.js";
|
|
4
|
+
import { viaAgent } from "./errors.js";
|
|
5
|
+
import { named } from "./summary.js";
|
|
6
|
+
/**
|
|
7
|
+
* Runs a write that may carry the person's card values (platform web parity spec §4.3): inside
|
|
8
|
+
* `ctx.personInputs.apply` when the approved call asked for person fields, so the sealed values
|
|
9
|
+
* are consumed in the write's own transaction, else directly with none. `write` gets the values
|
|
10
|
+
* by dot path and the audit detail: `viaAgent(operation)` plus `inputsProvided` (the entered
|
|
11
|
+
* paths, never the values) when the person entered any (spec §10).
|
|
12
|
+
*/
|
|
13
|
+
export function withPersonInputs(operation, ctx, write) {
|
|
14
|
+
const base = viaAgent(operation, ctx);
|
|
15
|
+
if (ctx.personInputs === undefined)
|
|
16
|
+
return write({}, base);
|
|
17
|
+
return ctx.personInputs.apply((values) => write(values, { ...base, inputsProvided: Object.keys(values).sort() }));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Ruling R11 (platform web parity plan): the one exception to "the write runs inside
|
|
21
|
+
* `personInputs.apply`". The catalog install runs `requires_new` steps that take the org row lock;
|
|
22
|
+
* inside `apply`, `connectors.create` would take that lock in the consuming transaction and the
|
|
23
|
+
* next step would wait on it for good. Such a write takes the values first and runs outside.
|
|
24
|
+
*
|
|
25
|
+
* The person's card values for a write that cannot run inside the consuming transaction: one made
|
|
26
|
+
* of several transactions of its own (`requires_new` steps under the org row lock, such as the
|
|
27
|
+
* catalog install), which would wait on a lock the consuming transaction holds. The values are
|
|
28
|
+
* consumed in a short transaction of their own and returned with the audit detail
|
|
29
|
+
* ({@link withPersonInputs}'s); the write then runs outside it. A write that fails after this
|
|
30
|
+
* leaves nothing to retry with: the call is made again, with a new card, like any failed call.
|
|
31
|
+
*/
|
|
32
|
+
export async function takePersonInputs(operation, ctx) {
|
|
33
|
+
return withPersonInputs(operation, ctx, async (entered, auditDetail) => ({
|
|
34
|
+
entered: { ...entered },
|
|
35
|
+
auditDetail,
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
/** What the model is told after a failed write consumed the person's values. */
|
|
39
|
+
export const VALUES_USED_UP_TEXT = "The values the person entered were used up: calling the operation again shows a new card where the person enters them again.";
|
|
40
|
+
/**
|
|
41
|
+
* The error of a write that failed after {@link takePersonInputs} consumed the values: the same
|
|
42
|
+
* error (an `ApiError` keeps its code and details, a `ToolError` its kind), its message saying the
|
|
43
|
+
* values are gone and the person enters them again on a new card. Any other error becomes a
|
|
44
|
+
* `ToolError` naming only its class (as the pipeline would), with the original as `cause`.
|
|
45
|
+
*/
|
|
46
|
+
export function afterTaken(e, entered) {
|
|
47
|
+
if (Object.keys(entered).length === 0)
|
|
48
|
+
return e;
|
|
49
|
+
const told = (message) => `${message.trim().replace(/\.?$/, ".")} ${VALUES_USED_UP_TEXT}`;
|
|
50
|
+
if (e instanceof ApiError)
|
|
51
|
+
return new ApiError(e.code, told(e.message), e.details);
|
|
52
|
+
if (e instanceof ToolError)
|
|
53
|
+
return new ToolError(told(e.message), { kind: e.kind });
|
|
54
|
+
const name = e instanceof Error ? e.name : "Error";
|
|
55
|
+
const out = new ToolError(told(`The write failed (${name})`));
|
|
56
|
+
Object.defineProperty(out, "cause", { value: e });
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The values under `prefix` (`connectors.<templateId>.`), keyed by the rest of their path.
|
|
61
|
+
*/
|
|
62
|
+
export function enteredUnder(entered, prefix) {
|
|
63
|
+
return Object.fromEntries(Object.entries(entered)
|
|
64
|
+
.filter(([p]) => p.startsWith(prefix))
|
|
65
|
+
.map(([p, v]) => [p.slice(prefix.length), v]));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The `values` of a config route keyed by field dot path (deployment config, the org's copy): the
|
|
69
|
+
* model's non-secret values, the person's entered secrets, and `null` (clear) for each path in
|
|
70
|
+
* `clear`. A secret left out keeps its stored value, as on the web form.
|
|
71
|
+
*/
|
|
72
|
+
export function flatValues(values, entered, clear) {
|
|
73
|
+
return {
|
|
74
|
+
...values,
|
|
75
|
+
...entered,
|
|
76
|
+
...Object.fromEntries(clear.map((p) => [p, null])),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The whole org config (`config` of `PUT /orgs/:orgId/extensions/:extension`, a nested object): the
|
|
81
|
+
* model's non-secret config with the person's entered secrets set at their dot paths and `null`
|
|
82
|
+
* (clear) at each path in `clear`. A secret left out keeps its stored value.
|
|
83
|
+
*/
|
|
84
|
+
export function nestedConfig(values, entered, clear) {
|
|
85
|
+
const config = structuredClone(values);
|
|
86
|
+
for (const [path, v] of Object.entries(entered))
|
|
87
|
+
setDeep(config, path, v);
|
|
88
|
+
for (const path of clear)
|
|
89
|
+
setDeep(config, path, null);
|
|
90
|
+
return config;
|
|
91
|
+
}
|
|
92
|
+
/** Leaf `path=value` pairs of a values object (dot paths), each clipped for a card. */
|
|
93
|
+
function pairsOf(values, prefix = "") {
|
|
94
|
+
return Object.entries(values).flatMap(([k, v]) => {
|
|
95
|
+
const path = prefix === "" ? k : `${prefix}.${k}`;
|
|
96
|
+
if (typeof v === "object" && v !== null && !Array.isArray(v)) {
|
|
97
|
+
return pairsOf(v, path);
|
|
98
|
+
}
|
|
99
|
+
return [named(`${path}=${JSON.stringify(v)}`)];
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The card text of a config write: the non-secret values it sets, the secrets the person enters
|
|
104
|
+
* and the secrets it clears (paths only), e.g. `baseUrl="https://…"; the person enters apiKey`.
|
|
105
|
+
* The entered secrets are the plan's (`ctx.personAsk`: required secrets the call did not name
|
|
106
|
+
* included), else the call's `askPerson`.
|
|
107
|
+
*/
|
|
108
|
+
export function configChanges(i, ctx) {
|
|
109
|
+
const { values, clearSecrets: clear } = i;
|
|
110
|
+
const ask = ctx.personAsk ?? i.askPerson;
|
|
111
|
+
const set = pairsOf(values);
|
|
112
|
+
const zh = [];
|
|
113
|
+
const en = [];
|
|
114
|
+
if (set.length > 0) {
|
|
115
|
+
zh.push(`设置 ${set.join(",")}`);
|
|
116
|
+
en.push(`sets ${set.join(", ")}`);
|
|
117
|
+
}
|
|
118
|
+
if (ask.length > 0) {
|
|
119
|
+
zh.push(`由本人填写 ${ask.map(named).join("、")}`);
|
|
120
|
+
en.push(`the person enters ${ask.map(named).join(", ")}`);
|
|
121
|
+
}
|
|
122
|
+
if (clear.length > 0) {
|
|
123
|
+
zh.push(`清除 ${clear.map(named).join("、")}`);
|
|
124
|
+
en.push(`clears ${clear.map(named).join(", ")}`);
|
|
125
|
+
}
|
|
126
|
+
if (zh.length === 0)
|
|
127
|
+
return { zh: "不改动任何字段", en: "changes no field" };
|
|
128
|
+
return { zh: zh.join(";"), en: en.join("; ") };
|
|
129
|
+
}
|
|
@@ -8,7 +8,9 @@ import { ExtensionAvailability } from "../../extensions/unavailable.js";
|
|
|
8
8
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
9
9
|
import { PlatformOperations } from "../registry.js";
|
|
10
10
|
export { OTHER_ORG } from "./other-orgs.js";
|
|
11
|
-
export declare const NEEDS_INPUT = "This plugin needs
|
|
11
|
+
export declare const NEEDS_INPUT = "This plugin needs connector input (endpoints, credentials): install it with plugins.install, or for an installed plugin missing connectors create them with plugins.configure-connectors; the person enters the credentials on the confirmation card.";
|
|
12
|
+
/** `plugin.needs_input` when what is missing is its extension's org config (an agent can set it). */
|
|
13
|
+
export declare const needsOrgConfig: (extension: string) => string;
|
|
12
14
|
/**
|
|
13
15
|
* Plugin operations of the `Platform` tool (spec §7): the org's view (list, get, switch on or off)
|
|
14
16
|
* and the super admin's platform view (list, get, update with its preview). Every platform result
|