@capybara-hq/plugin-sdk 0.1.0-rc.28 → 0.1.0-rc.29

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.
@@ -97,6 +97,11 @@ export interface ConnectorOpenArgs {
97
97
  /** Called once on a 401; after the kernel refreshes credentials the plugin retries once. */
98
98
  onUnauthorized: () => Promise<void>;
99
99
  signal: AbortSignal;
100
+ /**
101
+ * The org this session serves. Pass it to `ctx.net.fetch` as `opts.orgId` for every request to
102
+ * the endpoint, so the org's allowed internal endpoints apply (and no other org's).
103
+ */
104
+ orgId: string;
100
105
  /**
101
106
  * Called when the remote reports during the session that its tool list changed (e.g. MCP
102
107
  * `notifications/tools/list_changed`), possibly several times; the kernel schedules one
@@ -180,10 +185,12 @@ export interface Connector {
180
185
  * preview), returning the declared auth methods and an optional operation list.
181
186
  * `endpoint` is already validated against endpointSchema. On failure throw ToolError (message in
182
187
  * English, no credentials). Old connectors do not implement it; the kernel must check for
183
- * absence.
188
+ * absence. `orgId` is the org the preview runs for: pass it to `ctx.net.fetch` as `opts.orgId`
189
+ * for every request to the endpoint, as with `ConnectorOpenArgs.orgId`.
184
190
  */
185
191
  inspect?(args: {
186
192
  endpoint: unknown;
187
193
  signal: AbortSignal;
194
+ orgId: string;
188
195
  }): Promise<ConnectorInspection>;
189
196
  }
package/dist/ctx.d.ts CHANGED
@@ -3,6 +3,7 @@ import type { ExtensionPointRef } from "./extension-point.js";
3
3
  import type { AvailableHook, HookHandler, HookOptions } from "./hooks.js";
4
4
  import type { RouteCaller } from "./http-access.js";
5
5
  import type { ModelEmbeddingInfo, ModelKind } from "./model.js";
6
+ import type { ExtensionNet } from "./net.js";
6
7
  import type { SetupCheckDefinition } from "./setup-check.js";
7
8
  import type { ObjectHead, PresignedUpload, PresignGetOptions } from "./storage.js";
8
9
  import type { ToolHandler, ToolSpec } from "./tool.js";
@@ -166,6 +167,11 @@ export interface ExtensionContext {
166
167
  storage: ExtensionStorage;
167
168
  /** Models by purpose (requires `permissions.models`, see {@link ExtensionModels}). */
168
169
  models: ExtensionModels;
170
+ /**
171
+ * Guarded HTTP for URLs a person supplied (see {@link ExtensionNet}): a connector endpoint or an
172
+ * org-overridable base URL goes through `ctx.net.fetch`, never the global `fetch`.
173
+ */
174
+ net: ExtensionNet;
169
175
  /** A Kysely instance already switched to this plugin's schema (withSchema). */
170
176
  db: Kysely<any>;
171
177
  http: {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "0.1.0-rc.28";
1
+ export declare const SDK_VERSION = "0.1.0-rc.29";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./bootstrap.js";
4
4
  export * from "./cards.js";
@@ -22,6 +22,7 @@ export * from "./identity.js";
22
22
  export * from "./marketplace.js";
23
23
  export * from "./model.js";
24
24
  export * from "./model-params.js";
25
+ export * from "./net.js";
25
26
  export * from "./org-access.js";
26
27
  export * from "./permissions.js";
27
28
  export * from "./plugin-manifest.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export const SDK_VERSION = "0.1.0-rc.28";
1
+ export const SDK_VERSION = "0.1.0-rc.29";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./bootstrap.js";
4
4
  export * from "./cards.js";
@@ -22,6 +22,7 @@ export * from "./identity.js";
22
22
  export * from "./marketplace.js";
23
23
  export * from "./model.js";
24
24
  export * from "./model-params.js";
25
+ export * from "./net.js";
25
26
  export * from "./org-access.js";
26
27
  export * from "./permissions.js";
27
28
  export * from "./plugin-manifest.js";
package/dist/net.d.ts ADDED
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Guarded outbound HTTP for URLs a person supplied (`ctx.net`).
3
+ *
4
+ * Rule: a request whose host comes from a person or from config an org admin or member can set (a
5
+ * connector endpoint, an org-overridable base URL) goes through `ctx.net.fetch`, never the global
6
+ * `fetch`; a fixed vendor host, or a URL only the super admin can set, may keep `fetch`.
7
+ */
8
+ /** Why `ctx.net.fetch` refused a request (the codes of the kernel's guarded client). */
9
+ export type NetDeniedCode = "net.insecure_url" | "net.private_address" | "net.dns_failed" | "net.redirect" | "net.proxy_refused";
10
+ /**
11
+ * The request was refused by the kernel's network rules; `message` is English and names `host`.
12
+ * Detect it with {@link isNetDeniedError} (by `name`), never `instanceof`, which fails across
13
+ * package copies. Map it to the plugin's own actionable error (a connector's `ToolError`, a
14
+ * provider's `ModelError` of kind `invalid_request`).
15
+ */
16
+ export declare class NetDeniedError extends Error {
17
+ readonly code: NetDeniedCode;
18
+ readonly host: string;
19
+ /** The HTTP status of a refused redirect (`net.redirect`); absent for the other codes. */
20
+ readonly status?: number | undefined;
21
+ readonly name: "NetDeniedError";
22
+ constructor(code: NetDeniedCode, host: string, message: string,
23
+ /** The HTTP status of a refused redirect (`net.redirect`); absent for the other codes. */
24
+ status?: number | undefined);
25
+ }
26
+ /** True for a {@link NetDeniedError} from any copy of the SDK or the kernel (checked by `name`). */
27
+ export declare function isNetDeniedError(e: unknown): e is NetDeniedError;
28
+ /**
29
+ * `ctx.net`: the kernel's guarded HTTP client, no permission needed. It needs a kernel that ships
30
+ * it: a plugin that calls it raises its manifest's minimum `sdk` to the SDK release that added it.
31
+ */
32
+ export interface ExtensionNet {
33
+ /**
34
+ * The global `fetch` signature with the kernel's network rules applied: https only, except plain
35
+ * http to an origin `http://host:port` a super admin allowed for `opts.orgId`, and to loopback
36
+ * under the kernel's tests-only `net.allowInsecureLoopback`; private, loopback and link-local
37
+ * addresses refused (link-local always), the address checked when the connection is made (no
38
+ * DNS-rebinding window); the deployment's egress proxy honoured. An http URL to a host the org
39
+ * allows only as a hostname entry (https only) is refused with a message that names the
40
+ * `http://host:port` origin entry which would allow it. Redirects
41
+ * are never followed: with `redirect: "manual"` a 3xx response is returned as is, otherwise a 3xx
42
+ * rejects with `net.redirect`. Bodies stream; no size cap. `init.signal` is combined with
43
+ * `ctx.signal`.
44
+ *
45
+ * `opts.orgId` is the org the request is made for (e.g. `ConnectorOpenArgs.orgId`): only then may
46
+ * the target be one of the internal endpoints a super admin allowed for that org. Without it only
47
+ * public addresses are reachable. A refusal rejects with {@link NetDeniedError}.
48
+ */
49
+ fetch(url: string, init?: RequestInit, opts?: {
50
+ orgId?: string;
51
+ }): Promise<Response>;
52
+ }
package/dist/net.js ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Guarded outbound HTTP for URLs a person supplied (`ctx.net`).
3
+ *
4
+ * Rule: a request whose host comes from a person or from config an org admin or member can set (a
5
+ * connector endpoint, an org-overridable base URL) goes through `ctx.net.fetch`, never the global
6
+ * `fetch`; a fixed vendor host, or a URL only the super admin can set, may keep `fetch`.
7
+ */
8
+ /**
9
+ * The request was refused by the kernel's network rules; `message` is English and names `host`.
10
+ * Detect it with {@link isNetDeniedError} (by `name`), never `instanceof`, which fails across
11
+ * package copies. Map it to the plugin's own actionable error (a connector's `ToolError`, a
12
+ * provider's `ModelError` of kind `invalid_request`).
13
+ */
14
+ export class NetDeniedError extends Error {
15
+ code;
16
+ host;
17
+ status;
18
+ name = "NetDeniedError";
19
+ constructor(code, host, message,
20
+ /** The HTTP status of a refused redirect (`net.redirect`); absent for the other codes. */
21
+ status) {
22
+ super(message);
23
+ this.code = code;
24
+ this.host = host;
25
+ this.status = status;
26
+ }
27
+ }
28
+ /** True for a {@link NetDeniedError} from any copy of the SDK or the kernel (checked by `name`). */
29
+ export function isNetDeniedError(e) {
30
+ if (typeof e !== "object" || e === null)
31
+ return false;
32
+ const o = e;
33
+ return o.name === "NetDeniedError" && typeof o.code === "string" && typeof o.host === "string";
34
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-sdk",
3
- "version": "0.1.0-rc.28",
3
+ "version": "0.1.0-rc.29",
4
4
  "description": "Capybara plugin SDK: the types and pure functions plugins are written against",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {