@capybara-hq/plugin-sdk 0.1.0-rc.22 → 0.1.0-rc.23
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/ctx.d.ts +7 -2
- package/dist/http-access.d.ts +52 -0
- package/dist/http-access.js +12 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/permissions.d.ts +3 -6
- package/dist/permissions.js +18 -4
- package/package.json +1 -1
package/dist/ctx.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Kysely } from "kysely";
|
|
2
2
|
import type { ExtensionPointRef } from "./extension-point.js";
|
|
3
3
|
import type { AvailableHook, HookHandler, HookOptions } from "./hooks.js";
|
|
4
|
+
import type { RouteCaller } from "./http-access.js";
|
|
4
5
|
import type { ModelEmbeddingInfo, ModelKind } from "./model.js";
|
|
5
6
|
import type { SetupCheckDefinition } from "./setup-check.js";
|
|
6
7
|
import type { ObjectHead, PresignedUpload, PresignGetOptions } from "./storage.js";
|
|
@@ -160,8 +161,12 @@ export interface ExtensionContext {
|
|
|
160
161
|
/** 已切到本插件 schema(withSchema)的 Kysely 实例。 */
|
|
161
162
|
db: Kysely<any>;
|
|
162
163
|
http: {
|
|
163
|
-
/**
|
|
164
|
-
|
|
164
|
+
/**
|
|
165
|
+
* Mounted at `/plugins/<name><path>` (`public`, `embed`) or `/plugins/<name>/orgs/:orgId<path>`
|
|
166
|
+
* (`member`, `admin`), as `permissions.http` declares. The kernel enforces the access before
|
|
167
|
+
* the handler runs and passes the resolved caller; trust only `caller`.
|
|
168
|
+
*/
|
|
169
|
+
route(method: "GET" | "POST" | "PUT" | "DELETE", path: string, handler: (req: Request, caller: RouteCaller) => Promise<Response>): void;
|
|
165
170
|
};
|
|
166
171
|
tools: {
|
|
167
172
|
/** 注册一个工具;只能在 `setup` 期间调用,名称不可重复。 */
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { UiRole } from "./ui.js";
|
|
2
|
+
/**
|
|
3
|
+
* Who may call an extension route (declared per route in `permissions.http`, enforced by the
|
|
4
|
+
* kernel before the handler runs and before the body is read):
|
|
5
|
+
*
|
|
6
|
+
* - `public`: anyone; unsafe methods are rate-limited per client IP. Mounted at
|
|
7
|
+
* `/plugins/<name><path>`.
|
|
8
|
+
* - `embed`: the holder of an embed token (see `ctx.ui`); path under `/ui/`. Mounted at
|
|
9
|
+
* `/plugins/<name><path>`.
|
|
10
|
+
* - `member` / `admin`: an org member (admin: org admin and up) with a personal access token.
|
|
11
|
+
* Mounted at `/plugins/<name>/orgs/:orgId<path>`.
|
|
12
|
+
*/
|
|
13
|
+
export declare const HTTP_ACCESS: readonly ["public", "embed", "member", "admin"];
|
|
14
|
+
export type HttpAccess = (typeof HTTP_ACCESS)[number];
|
|
15
|
+
/** One entry of `permissions.http`. */
|
|
16
|
+
export interface HttpPermission {
|
|
17
|
+
method: "GET" | "POST" | "PUT" | "DELETE";
|
|
18
|
+
path: string;
|
|
19
|
+
access: HttpAccess;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The caller the kernel resolved for a route, passed to the handler as its second argument.
|
|
23
|
+
* Trust only this (`caller.orgId`, never an org id in the body or query).
|
|
24
|
+
*/
|
|
25
|
+
export type RouteCaller = {
|
|
26
|
+
access: "public";
|
|
27
|
+
} | {
|
|
28
|
+
access: "embed";
|
|
29
|
+
scope: "org";
|
|
30
|
+
orgId: string;
|
|
31
|
+
accountId: string;
|
|
32
|
+
role: UiRole;
|
|
33
|
+
contribution: string;
|
|
34
|
+
conversationId?: string;
|
|
35
|
+
/** The token's expiry (Unix seconds): a long-lived response (SSE) ends by then. */
|
|
36
|
+
exp: number;
|
|
37
|
+
config: unknown;
|
|
38
|
+
} | {
|
|
39
|
+
access: "embed";
|
|
40
|
+
scope: "platform";
|
|
41
|
+
accountId: string;
|
|
42
|
+
role: "superAdmin";
|
|
43
|
+
contribution: string;
|
|
44
|
+
/** The token's expiry (Unix seconds): a long-lived response (SSE) ends by then. */
|
|
45
|
+
exp: number;
|
|
46
|
+
} | {
|
|
47
|
+
access: "member" | "admin";
|
|
48
|
+
orgId: string;
|
|
49
|
+
accountId: string;
|
|
50
|
+
role: UiRole;
|
|
51
|
+
config: unknown;
|
|
52
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who may call an extension route (declared per route in `permissions.http`, enforced by the
|
|
3
|
+
* kernel before the handler runs and before the body is read):
|
|
4
|
+
*
|
|
5
|
+
* - `public`: anyone; unsafe methods are rate-limited per client IP. Mounted at
|
|
6
|
+
* `/plugins/<name><path>`.
|
|
7
|
+
* - `embed`: the holder of an embed token (see `ctx.ui`); path under `/ui/`. Mounted at
|
|
8
|
+
* `/plugins/<name><path>`.
|
|
9
|
+
* - `member` / `admin`: an org member (admin: org admin and up) with a personal access token.
|
|
10
|
+
* Mounted at `/plugins/<name>/orgs/:orgId<path>`.
|
|
11
|
+
*/
|
|
12
|
+
export const HTTP_ACCESS = ["public", "embed", "member", "admin"];
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.1.0-rc.
|
|
1
|
+
export declare const SDK_VERSION = "0.1.0-rc.23";
|
|
2
2
|
export * from "./agent-template.js";
|
|
3
3
|
export * from "./bootstrap.js";
|
|
4
4
|
export * from "./cards.js";
|
|
@@ -17,6 +17,7 @@ export * from "./extension-point.js";
|
|
|
17
17
|
export * from "./file-preview.js";
|
|
18
18
|
export * from "./git-hosts.js";
|
|
19
19
|
export * from "./hooks.js";
|
|
20
|
+
export * from "./http-access.js";
|
|
20
21
|
export * from "./identity.js";
|
|
21
22
|
export * from "./marketplace.js";
|
|
22
23
|
export * from "./model.js";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.1.0-rc.
|
|
1
|
+
export const SDK_VERSION = "0.1.0-rc.23";
|
|
2
2
|
export * from "./agent-template.js";
|
|
3
3
|
export * from "./bootstrap.js";
|
|
4
4
|
export * from "./cards.js";
|
|
@@ -17,6 +17,7 @@ export * from "./extension-point.js";
|
|
|
17
17
|
export * from "./file-preview.js";
|
|
18
18
|
export * from "./git-hosts.js";
|
|
19
19
|
export * from "./hooks.js";
|
|
20
|
+
export * from "./http-access.js";
|
|
20
21
|
export * from "./identity.js";
|
|
21
22
|
export * from "./marketplace.js";
|
|
22
23
|
export * from "./model.js";
|
package/dist/permissions.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { type PolicyHook } from "./hooks.js";
|
|
2
|
+
import { type HttpPermission } from "./http-access.js";
|
|
2
3
|
/** Extension permission manifest: governance, not a sandbox; using an undeclared platform API throws ExtensionPermissionError. */
|
|
3
4
|
export interface ExtensionPermissions {
|
|
4
5
|
/** ctx.secrets */
|
|
5
6
|
secrets?: boolean;
|
|
6
|
-
/** ctx.http.route
|
|
7
|
-
http?:
|
|
8
|
-
method: "GET" | "POST" | "PUT" | "DELETE";
|
|
9
|
-
path: string;
|
|
10
|
-
public?: boolean;
|
|
11
|
-
}[];
|
|
7
|
+
/** Routes registered with ctx.http.route; each declares who may call it (`access`). */
|
|
8
|
+
http?: HttpPermission[];
|
|
12
9
|
/** ctx.tools.register 的工具名。 */
|
|
13
10
|
tools?: string[];
|
|
14
11
|
/**
|
package/dist/permissions.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { POLICY_HOOKS } from "./hooks.js";
|
|
2
|
+
import { HTTP_ACCESS } from "./http-access.js";
|
|
2
3
|
import { SETUP_CHECK_ID_RE, SETUP_CHECK_LIMITS } from "./setup-check.js";
|
|
3
4
|
import { UI_ICONS } from "./ui.js";
|
|
4
5
|
import { PLACE_SLOTS, parseSlotRef, uiSlot } from "./ui-slots.js";
|
|
@@ -117,14 +118,27 @@ export function validatePermissions(plugin, p) {
|
|
|
117
118
|
!METHODS.has(r.method) ||
|
|
118
119
|
typeof r.path !== "string" ||
|
|
119
120
|
!r.path.startsWith("/") ||
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
typeof r.access !== "string" ||
|
|
122
|
+
!HTTP_ACCESS.includes(r.access)) {
|
|
123
|
+
errs.push("permissions.http entries need method GET/POST/PUT/DELETE, a path starting with /, and access public/embed/member/admin");
|
|
122
124
|
continue;
|
|
123
125
|
}
|
|
124
126
|
const key = `${r.method} ${r.path}`;
|
|
125
127
|
if (seen.has(key))
|
|
126
128
|
errs.push(`permissions.http has duplicate route "${key}"`);
|
|
127
129
|
seen.add(key);
|
|
130
|
+
if (r.path === "/orgs" || r.path.startsWith("/orgs/")) {
|
|
131
|
+
errs.push(`permissions.http route "${key}" must not start with /orgs/ (reserved for org routes)`);
|
|
132
|
+
}
|
|
133
|
+
if (r.access === "embed" && !r.path.startsWith(UI_EMBED_PREFIX)) {
|
|
134
|
+
errs.push(`permissions.http embed route "${key}" must be under ${UI_EMBED_PREFIX}`);
|
|
135
|
+
}
|
|
136
|
+
if ((r.access === "member" || r.access === "admin") &&
|
|
137
|
+
// anywhere, not only after a slash: find-my-way lets a later duplicate param win, so
|
|
138
|
+
// `/x-:orgId` would override the mount's `:orgId`
|
|
139
|
+
/:orgId(?![A-Za-z0-9_])/.test(r.path)) {
|
|
140
|
+
errs.push(`permissions.http route "${key}" must not contain :orgId (the org comes from the mount)`);
|
|
141
|
+
}
|
|
128
142
|
}
|
|
129
143
|
}
|
|
130
144
|
}
|
|
@@ -220,7 +234,7 @@ export function validateUiContributions(ui, permissions) {
|
|
|
220
234
|
multiListed.add(id);
|
|
221
235
|
}
|
|
222
236
|
const gets = new Set((Array.isArray(perms.http) ? perms.http : [])
|
|
223
|
-
.filter((r) => isObj(r) && r.method === "GET")
|
|
237
|
+
.filter((r) => isObj(r) && r.method === "GET" && r.access === "public")
|
|
224
238
|
.map((r) => r.path));
|
|
225
239
|
const errs = [];
|
|
226
240
|
for (const id of multiListed)
|
|
@@ -310,7 +324,7 @@ export function validateUiContributions(ui, permissions) {
|
|
|
310
324
|
errs.push(`ui "${id}" (embed) path must start with "${UI_EMBED_PREFIX}"`);
|
|
311
325
|
}
|
|
312
326
|
else if (!gets.has(c.path)) {
|
|
313
|
-
errs.push(`ui "${id}"
|
|
327
|
+
errs.push(`ui "${id}" embed path "${c.path}" must be declared in permissions.http as GET with access public`);
|
|
314
328
|
}
|
|
315
329
|
});
|
|
316
330
|
const aliasIds = new Set(aliases.map((a) => a.id));
|