@capybara-hq/plugin-sdk 0.1.0-rc.6 → 0.1.0-rc.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/README.md +1 -1
  2. package/agent-docs/agent-templates.md +14 -2
  3. package/agent-docs/concepts.md +14 -5
  4. package/agent-docs/connector-templates.md +7 -1
  5. package/agent-docs/extension-points/channel.md +1 -1
  6. package/agent-docs/extension-points/context.md +15 -0
  7. package/agent-docs/extension-points/device-provider.md +15 -0
  8. package/agent-docs/extension-points/file-preview.md +2 -0
  9. package/agent-docs/extension-points/model-provider.md +3 -1
  10. package/agent-docs/extension-points/object-store.md +2 -0
  11. package/agent-docs/extension-points/push-provider.md +17 -0
  12. package/agent-docs/extensions.md +29 -3
  13. package/agent-docs/plugin-format.md +52 -2
  14. package/agent-docs/setup.md +54 -0
  15. package/dist/agent-template.d.ts +15 -6
  16. package/dist/agent-template.js +32 -13
  17. package/dist/avatar-presets.d.ts +8 -0
  18. package/dist/avatar-presets.js +17 -0
  19. package/dist/bootstrap.d.ts +109 -1
  20. package/dist/bootstrap.js +185 -2
  21. package/dist/cards.d.ts +67 -13
  22. package/dist/cards.js +91 -21
  23. package/dist/channel.d.ts +148 -48
  24. package/dist/channel.js +10 -5
  25. package/dist/client-css.d.ts +36 -0
  26. package/dist/client-css.js +326 -0
  27. package/dist/client-section.d.ts +35 -0
  28. package/dist/client-section.js +133 -0
  29. package/dist/config-ui.d.ts +22 -0
  30. package/dist/config-ui.js +64 -4
  31. package/dist/connector-auth.d.ts +15 -2
  32. package/dist/connector-auth.js +97 -8
  33. package/dist/connector.d.ts +74 -32
  34. package/dist/context.d.ts +40 -0
  35. package/dist/context.js +2 -0
  36. package/dist/ctx.d.ts +132 -29
  37. package/dist/define-extension.d.ts +26 -12
  38. package/dist/define-extension.js +12 -5
  39. package/dist/device-denied-paths.d.ts +18 -0
  40. package/dist/device-denied-paths.js +84 -0
  41. package/dist/device-operation.d.ts +333 -0
  42. package/dist/device-operation.js +312 -0
  43. package/dist/device-protocol.d.ts +285 -50
  44. package/dist/device-protocol.js +755 -90
  45. package/dist/device-provider.d.ts +503 -0
  46. package/dist/device-provider.js +302 -0
  47. package/dist/dial-in.d.ts +176 -0
  48. package/dist/dial-in.js +115 -0
  49. package/dist/extension-point.d.ts +2 -0
  50. package/dist/extension-point.js +6 -2
  51. package/dist/file-preview.d.ts +23 -6
  52. package/dist/git-hosts.d.ts +53 -0
  53. package/dist/git-hosts.js +98 -0
  54. package/dist/hooks.d.ts +125 -20
  55. package/dist/hooks.js +5 -0
  56. package/dist/http-access.d.ts +62 -0
  57. package/dist/http-access.js +12 -0
  58. package/dist/identity.d.ts +38 -9
  59. package/dist/identity.js +21 -1
  60. package/dist/index.d.ts +29 -3
  61. package/dist/index.js +29 -3
  62. package/dist/marketplace.d.ts +26 -0
  63. package/dist/marketplace.js +43 -1
  64. package/dist/model-params.d.ts +41 -22
  65. package/dist/model-params.js +28 -15
  66. package/dist/model.d.ts +206 -71
  67. package/dist/model.js +152 -19
  68. package/dist/net.d.ts +52 -0
  69. package/dist/net.js +34 -0
  70. package/dist/network-classes.d.ts +98 -0
  71. package/dist/network-classes.js +291 -0
  72. package/dist/permissions.d.ts +54 -22
  73. package/dist/permissions.js +119 -43
  74. package/dist/plugin-manifest.d.ts +45 -5
  75. package/dist/plugin-manifest.js +174 -6
  76. package/dist/plugin-package.d.ts +82 -38
  77. package/dist/plugin-package.js +61 -29
  78. package/dist/push.d.ts +75 -0
  79. package/dist/push.js +87 -0
  80. package/dist/sandbox-linux-runtime-source.d.ts +1 -0
  81. package/dist/sandbox-linux-runtime-source.js +2318 -0
  82. package/dist/sandbox-native-runtime-source.d.ts +10 -0
  83. package/dist/sandbox-native-runtime-source.js +476 -0
  84. package/dist/sandbox-runtime-source.d.ts +19 -0
  85. package/dist/sandbox-runtime-source.js +28 -0
  86. package/dist/sandbox-write-denies.d.ts +139 -0
  87. package/dist/sandbox-write-denies.js +869 -0
  88. package/dist/secret.d.ts +4 -1
  89. package/dist/secret.js +4 -1
  90. package/dist/setup-check.d.ts +128 -0
  91. package/dist/setup-check.js +142 -0
  92. package/dist/setup-guide-parse.d.ts +121 -0
  93. package/dist/setup-guide-parse.js +356 -0
  94. package/dist/setup-guide-render.d.ts +45 -0
  95. package/dist/setup-guide-render.js +351 -0
  96. package/dist/setup-guide.d.ts +108 -0
  97. package/dist/setup-guide.js +367 -0
  98. package/dist/shell-capabilities.d.ts +211 -0
  99. package/dist/shell-capabilities.js +44 -0
  100. package/dist/shell-environment.d.ts +57 -0
  101. package/dist/shell-environment.js +21 -0
  102. package/dist/skill.d.ts +27 -17
  103. package/dist/skill.js +40 -26
  104. package/dist/storage.d.ts +52 -25
  105. package/dist/svg-viewbox.d.ts +10 -0
  106. package/dist/svg-viewbox.js +24 -0
  107. package/dist/theme-assets.d.ts +55 -0
  108. package/dist/theme-assets.js +489 -0
  109. package/dist/theme-readability.d.ts +37 -0
  110. package/dist/theme-readability.js +145 -0
  111. package/dist/theme-tokens.generated.d.ts +299 -0
  112. package/dist/theme-tokens.generated.js +184 -0
  113. package/dist/theme.d.ts +190 -0
  114. package/dist/theme.js +471 -0
  115. package/dist/tool.d.ts +99 -26
  116. package/dist/tool.js +29 -9
  117. package/dist/ui-parts.d.ts +23 -0
  118. package/dist/ui-parts.js +385 -0
  119. package/dist/ui-resolve.d.ts +35 -0
  120. package/dist/ui-resolve.js +42 -0
  121. package/dist/ui-slots.d.ts +65 -0
  122. package/dist/ui-slots.js +261 -0
  123. package/dist/ui.d.ts +212 -76
  124. package/dist/ui.js +101 -27
  125. package/dist/url.d.ts +4 -1
  126. package/dist/url.js +4 -1
  127. package/package.json +13 -1
  128. package/schemas/bootstrap-extra.v1.schema.json +186 -0
  129. package/schemas/bootstrap.v1.schema.json +20 -0
  130. package/schemas/connector-template.v1.schema.json +35 -0
  131. package/schemas/marketplace.v1.schema.json +14 -0
  132. package/schemas/plugin.v1.schema.json +122 -3
  133. package/schemas/theme.v1.schema.json +302 -0
  134. package/agent-docs/extension-points/sandbox.md +0 -15
  135. package/dist/sandbox.d.ts +0 -254
  136. package/dist/sandbox.js +0 -153
package/dist/model.js CHANGED
@@ -1,23 +1,33 @@
1
- /** 图片块接受的类型。 */
1
+ /** The aspect ratios a caller may ask for instead of an exact size. */
2
+ export const IMAGE_ASPECT_RATIOS = ["1:1", "4:3", "3:4", "3:2", "2:3", "16:9", "9:16"];
3
+ /** Types accepted by image blocks. */
2
4
  export const IMAGE_MEDIA_TYPES = ["image/png", "image/jpeg", "image/gif", "image/webp"];
3
- /** 文档块接受的类型。 */
5
+ /** Types accepted by document blocks. */
4
6
  export const DOCUMENT_MEDIA_TYPES = [
5
7
  "application/pdf",
6
8
  "text/plain",
7
9
  "text/markdown",
8
10
  "text/csv",
9
11
  ];
10
- /** 单个媒体块解码后的字节上限(按主流供应商的较小值取)。 */
12
+ /**
13
+ * Upper bound on the decoded bytes of a single media block (the smaller value among mainstream
14
+ * vendors).
15
+ */
11
16
  export const MEDIA_LIMITS = { imageBytes: 5_242_880, documentBytes: 33_554_432 };
12
17
  const B64_RE = /^[A-Za-z0-9+/]*={0,2}$/;
13
18
  const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
14
- /** 媒体块 `name` 的最大长度(字符)。 */
19
+ /** Maximum length (characters) of a media block's `name`. */
15
20
  export const MEDIA_NAME_MAX_CHARS = 255;
16
- /** 供应商请求里文件名 / 标题的建议上限(码点),{@link clipMediaName} 的默认值。 */
21
+ /**
22
+ * Suggested upper bound (code points) for file names / titles in vendor requests, the default of
23
+ * {@link clipMediaName}.
24
+ */
17
25
  export const PROVIDER_MEDIA_NAME_MAX = 200;
18
26
  /**
19
- * 把附件名截到 `max` 个码点以内(供应商映射用:有的接口对 filename / title 有长度限制,补后缀后还会更长)。
20
- * 尽量保留扩展名(不超过 16 个字符的 `.ext`),中间用 `…` 表示截掉的部分。纯函数。
27
+ * Truncates an attachment name to at most `max` code points (for vendor mapping: some APIs limit
28
+ * filename / title length, and adding a suffix makes it longer still).
29
+ * Keeps the extension where possible (a `.ext` of at most 16 characters), with `…` marking the cut
30
+ * part in the middle. A pure function.
21
31
  */
22
32
  export function clipMediaName(name, max = PROVIDER_MEDIA_NAME_MAX) {
23
33
  const cps = [...name];
@@ -29,7 +39,7 @@ export function clipMediaName(name, max = PROVIDER_MEDIA_NAME_MAX) {
29
39
  const head = cps.slice(0, max - 1 - keep.length);
30
40
  return `${head.join("")}…${keep.join("")}`;
31
41
  }
32
- /** 是否含控制字符(C0、DEL 与 C1)。 */
42
+ /** Whether it contains control characters (C0, DEL and C1). */
33
43
  export function hasControlChars(s) {
34
44
  for (let i = 0; i < s.length; i++) {
35
45
  const c = s.charCodeAt(i);
@@ -38,18 +48,26 @@ export function hasControlChars(s) {
38
48
  }
39
49
  return false;
40
50
  }
41
- /** 附件 id 是否为 UUID(任意版本,大小写不限)。 */
51
+ /** Whether the attachment id is a UUID (any version, case-insensitive). */
42
52
  export function isAttachmentId(s) {
43
53
  return typeof s === "string" && UUID_RE.test(s);
44
54
  }
55
+ /** Any non-empty `type/subtype` (a `file` block's `mediaType`). */
56
+ const MEDIA_TYPE_RE = /^[^/\s]+\/[^/\s]+$/;
45
57
  const MEDIA = {
46
58
  image: { types: IMAGE_MEDIA_TYPES, limit: MEDIA_LIMITS.imageBytes },
47
59
  document: { types: DOCUMENT_MEDIA_TYPES, limit: MEDIA_LIMITS.documentBytes },
60
+ // A file the model cannot read: the kernel resolves it to text before the request, so no media
61
+ // type list applies. The byte ceiling is the one attachments already have.
62
+ file: { types: [], limit: MEDIA_LIMITS.documentBytes, anyType: true },
48
63
  };
49
64
  /**
50
- * 校验一个 image / document 块,返回错误列表(空表示合法):类型在列表里;`base64` 是标准、带填充、
51
- * 不含空白的 base64,解码后不超过 {@link MEDIA_LIMITS};`ref` 的 `attachmentId` 是 UUID;`name` 若有须是字符串、
52
- * 不超过 {@link MEDIA_NAME_MAX_CHARS} 个字符且不含控制字符。
65
+ * Validates an image / document / file block, returning a list of errors (empty means valid): the
66
+ * media type is in the block kind's list (`file` accepts any non-empty `type/subtype`); `base64` is
67
+ * standard, padded, whitespace-free base64 that decodes to at most {@link MEDIA_LIMITS}; a `ref`'s
68
+ * `attachmentId` is a UUID; `name`, when present, is a string of at most
69
+ * {@link MEDIA_NAME_MAX_CHARS} characters with no control characters; `size`, when present, is a
70
+ * non-negative integer (display metadata, never sent by a plugin).
53
71
  */
54
72
  export function validateMediaBlock(b) {
55
73
  if (typeof b !== "object" || b === null || Array.isArray(b))
@@ -57,9 +75,16 @@ export function validateMediaBlock(b) {
57
75
  const o = b;
58
76
  const spec = typeof o.type === "string" && Object.hasOwn(MEDIA, o.type) ? MEDIA[o.type] : undefined;
59
77
  if (!spec)
60
- return ['block type must be "image" or "document"'];
78
+ return ['block type must be "image", "document" or "file"'];
61
79
  const errs = [];
62
- if (typeof o.mediaType !== "string" || !spec.types.includes(o.mediaType)) {
80
+ if (spec.anyType) {
81
+ if (typeof o.mediaType !== "string" ||
82
+ !MEDIA_TYPE_RE.test(o.mediaType) ||
83
+ hasControlChars(o.mediaType)) {
84
+ errs.push(`${o.type} mediaType must be a non-empty type/subtype string`);
85
+ }
86
+ }
87
+ else if (typeof o.mediaType !== "string" || !spec.types.includes(o.mediaType)) {
63
88
  errs.push(`${o.type} mediaType must be one of ${spec.types.join(", ")}`);
64
89
  }
65
90
  if (o.name !== undefined) {
@@ -72,6 +97,10 @@ export function validateMediaBlock(b) {
72
97
  errs.push(`${o.type} name must not contain control characters`);
73
98
  }
74
99
  }
100
+ if (o.size !== undefined &&
101
+ (typeof o.size !== "number" || !Number.isInteger(o.size) || o.size < 0)) {
102
+ errs.push(`${o.type} size must be a non-negative integer`);
103
+ }
75
104
  const src = o.source;
76
105
  if (typeof src !== "object" || src === null) {
77
106
  errs.push(`${o.type} source must be an object`);
@@ -89,7 +118,8 @@ export function validateMediaBlock(b) {
89
118
  errs.push(`${o.type} source.data must be non-empty padded base64`);
90
119
  return errs;
91
120
  }
92
- // 先按长度算解码后的大小,超限就不再逐字符校验
121
+ // Compute the decoded size from the length first; when over the limit, skip the per-character
122
+ // validation
93
123
  const pad = data.endsWith("==") ? 2 : data.endsWith("=") ? 1 : 0;
94
124
  const bytes = (data.length / 4) * 3 - pad;
95
125
  if (bytes > spec.limit) {
@@ -113,6 +143,7 @@ const ALL_KINDS = new Set([
113
143
  "auth",
114
144
  "invalid_request",
115
145
  "context_overflow",
146
+ "refusal",
116
147
  "aborted",
117
148
  ]);
118
149
  const RETRYABLE = new Set([
@@ -122,11 +153,13 @@ const RETRYABLE = new Set([
122
153
  "timeout",
123
154
  "network",
124
155
  ]);
125
- /** rate_limited / overloaded / server / timeout / network 为 true。 */
156
+ /** True for rate_limited / overloaded / server / timeout / network. */
126
157
  export function isRetryableKind(kind) {
127
158
  return RETRYABLE.has(kind);
128
159
  }
129
- /** 鸭子类型判断(不用 instanceof),兼容插件自带另一份 plugin-sdk 副本的情况。 */
160
+ /**
161
+ * Duck-typed check (no instanceof), compatible with a plugin bundling another copy of plugin-sdk.
162
+ */
130
163
  export function isModelError(e) {
131
164
  if (!(e instanceof Error))
132
165
  return false;
@@ -143,7 +176,7 @@ export class ModelError extends Error {
143
176
  if (opts?.retryAfterMs !== undefined)
144
177
  this.retryAfterMs = opts.retryAfterMs;
145
178
  }
146
- /** rate_limited / overloaded / server / timeout / network 为 true。 */
179
+ /** True for rate_limited / overloaded / server / timeout / network. */
147
180
  get retryable() {
148
181
  return isRetryableKind(this.kind);
149
182
  }
@@ -170,5 +203,105 @@ export function validateEmbedResult(req, info, res) {
170
203
  }
171
204
  return null;
172
205
  }
173
- export const MODEL_PROVIDER_EXTENSION_POINT = "model-provider@1";
206
+ const BASE64 = /^[A-Za-z0-9+/]+={0,2}$/;
207
+ /** True when `x` is a well-formed {@link ModelImageGenerationInfo}. */
208
+ export function isValidImageGenerationInfo(x) {
209
+ if (typeof x !== "object" || x === null)
210
+ return false;
211
+ const o = x;
212
+ const isSize = (s) => typeof s === "object" &&
213
+ s !== null &&
214
+ Number.isInteger(s.width) &&
215
+ Number.isInteger(s.height) &&
216
+ s.width > 0 &&
217
+ s.height > 0;
218
+ if (!Array.isArray(o.sizes) || o.sizes.length === 0 || !o.sizes.every(isSize))
219
+ return false;
220
+ if (!isSize(o.defaultSize))
221
+ return false;
222
+ const d = o.defaultSize;
223
+ if (!o.sizes.some((s) => s.width === d.width && s.height === d.height))
224
+ return false;
225
+ if (!Number.isInteger(o.maxImages) || o.maxImages < 1)
226
+ return false;
227
+ if (!Number.isInteger(o.maxReferenceImages) || o.maxReferenceImages < 0) {
228
+ return false;
229
+ }
230
+ return (Array.isArray(o.outputMediaTypes) &&
231
+ o.outputMediaTypes.length > 0 &&
232
+ o.outputMediaTypes.every((t) => IMAGE_MEDIA_TYPES.includes(t)));
233
+ }
234
+ /**
235
+ * Checks an image generation result against its request and the model's facts. Returns null when
236
+ * valid, else the reason: wrong image count, an undeclared media type, data that is not base64,
237
+ * or a `usage` that is not an object whose token counts (and `outputImages`, when present) are
238
+ * non-negative integers (a caller records usage from it, so it is checked before anything is).
239
+ */
240
+ export function validateImageGenerateResult(req, info, res) {
241
+ const images = res?.images;
242
+ if (!Array.isArray(images))
243
+ return "result has no images array";
244
+ if (images.length !== req.n)
245
+ return `expected ${req.n} images, got ${images.length}`;
246
+ for (let i = 0; i < images.length; i++) {
247
+ const img = images[i];
248
+ const type = img?.mediaType;
249
+ if (typeof type !== "string" || !info.outputMediaTypes.includes(type)) {
250
+ return `image ${i} has media type ${String(type)}, not one of ${info.outputMediaTypes.join(", ")}`;
251
+ }
252
+ if (typeof img?.data !== "string" || !BASE64.test(img.data)) {
253
+ return `image ${i} data is not base64`;
254
+ }
255
+ }
256
+ const usage = res.usage;
257
+ if (typeof usage !== "object" || usage === null)
258
+ return "result has no usage object";
259
+ const u = usage;
260
+ const count = (v) => typeof v === "number" && Number.isInteger(v) && v >= 0;
261
+ for (const field of ["inputTokens", "outputTokens", "cacheReadTokens", "cacheWriteTokens"]) {
262
+ if (!count(u[field]))
263
+ return `usage.${field} is ${String(u[field])}, not a non-negative integer`;
264
+ }
265
+ if (u.outputImages !== undefined && !count(u.outputImages)) {
266
+ return `usage.outputImages is ${String(u.outputImages)}, not a non-negative integer`;
267
+ }
268
+ return null;
269
+ }
270
+ /**
271
+ * Chooses an output size: an exact `size` must be one the model offers; an `aspectRatio` picks the
272
+ * closest declared ratio (ties by area closest to the default's, then declaration order); neither
273
+ * gives the default size.
274
+ */
275
+ export function pickImageSize(info, opts) {
276
+ const fmt = (s) => `${s.width}x${s.height}`;
277
+ const { size, aspectRatio } = opts;
278
+ if (size) {
279
+ const hit = info.sizes.find((s) => s.width === size.width && s.height === size.height);
280
+ if (hit)
281
+ return { ok: true, size: hit };
282
+ return {
283
+ ok: false,
284
+ error: `Size ${fmt(size)} is not offered by this model; use one of ${info.sizes.map(fmt).join(", ")}.`,
285
+ };
286
+ }
287
+ if (!aspectRatio)
288
+ return { ok: true, size: info.defaultSize };
289
+ const [rw, rh] = aspectRatio.split(":").map(Number);
290
+ const target = Math.log(rw / rh);
291
+ const area = info.defaultSize.width * info.defaultSize.height;
292
+ let best = info.defaultSize;
293
+ let bestDiff = Number.POSITIVE_INFINITY;
294
+ let bestArea = Number.POSITIVE_INFINITY;
295
+ for (const s of info.sizes) {
296
+ const diff = Math.abs(Math.log(s.width / s.height) - target);
297
+ const areaDiff = Math.abs(s.width * s.height - area);
298
+ if (diff < bestDiff - 1e-9 || (Math.abs(diff - bestDiff) <= 1e-9 && areaDiff < bestArea)) {
299
+ best = s;
300
+ bestDiff = diff;
301
+ bestArea = areaDiff;
302
+ }
303
+ }
304
+ return { ok: true, size: best };
305
+ }
306
+ /** The model provider extension point (the only version since `@1` was removed before 0.1.0). */
174
307
  export const MODEL_PROVIDER_EXTENSION_POINT_V2 = "model-provider@2";
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
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * The address classes of the sandbox network (approval-only profiles design, "Open network"): pure
3
+ * data plus {@link classifyAddress}. The device workers (macOS SRT, the Linux forwarder) and the
4
+ * cloud providers' egress proxies decide every sandboxed connection on the resolved address with
5
+ * this one table, so the classes cannot drift between them.
6
+ *
7
+ * The table ({@link ADDRESS_CLASS_RANGES}) is data a copy in another language can mirror (the Linux
8
+ * forwarder's Python): the class of an address is that of the longest-prefix range containing it.
9
+ * Every family ends with a catch-all, so the table is total.
10
+ */
11
+ /**
12
+ * The class of one IP address.
13
+ *
14
+ * - `public`: globally routable; the only class open in `open-public` mode.
15
+ * - `private`: `10/8`, `172.16/12`, `192.168/16`.
16
+ * - `cgnat`: `100.64/10`.
17
+ * - `ula`: IPv6 unique local `fc00::/7` (except the metadata address).
18
+ * - `link-local`: `169.254/16` and `fe80::/10` (except the metadata addresses).
19
+ * - `metadata`: cloud metadata endpoints (`169.254.169.254`, `fd00:ec2::254`).
20
+ * - `loopback`: `127/8`, `::1`.
21
+ * - `multicast`, `broadcast`, `unspecified` (`0/8`, `::`), `nat64` (the NAT64 prefixes),
22
+ * `reserved` (every other special-purpose range).
23
+ *
24
+ * The host's own interface addresses are not a class of the table: the worker that knows them
25
+ * closes them in addition (a placeholder in the table test).
26
+ */
27
+ export type AddressClass = "public" | "private" | "cgnat" | "ula" | "link-local" | "metadata" | "loopback" | "multicast" | "broadcast" | "unspecified" | "nat64" | "reserved";
28
+ /** Every class closed in `open-public` mode: reachable only by running outside the sandbox. */
29
+ export declare const OPEN_PUBLIC_DENIED_CLASSES: readonly AddressClass[];
30
+ /**
31
+ * One range of the address-class table. A range with `embeddedIpv4At` is an IPv6 form that carries
32
+ * an IPv4 address (v4-mapped, SIIT, v4-compatible, 6to4): the address classifies as the 32-bit IPv4
33
+ * address starting at that bit offset (from the most significant bit). The NAT64 prefixes are not
34
+ * such ranges: the design closes them whatever they embed.
35
+ */
36
+ export type AddressClassRange = {
37
+ readonly family: "ipv4" | "ipv6";
38
+ /** `address/prefix`, the address in its canonical lower-case form. */
39
+ readonly cidr: string;
40
+ readonly class: AddressClass;
41
+ } | {
42
+ readonly family: "ipv6";
43
+ readonly cidr: string;
44
+ readonly embeddedIpv4At: number;
45
+ };
46
+ /**
47
+ * The address-class table, most specific range first within each family (longest prefix wins).
48
+ * IPv4 follows the kernel's `net/public-address.ts` (and the sandbox-docker egress proxy); IPv6
49
+ * does too, plus closures the design adds: the well-known NAT64 prefixes (`64:ff9b::/96`,
50
+ * `64:ff9b:1::/48`) whatever they embed, `2001::/23` (Teredo, ORCHID and the other IETF
51
+ * assignments), `3fff::/20`, and everything outside global unicast `2000::/3`.
52
+ *
53
+ * Not covered: an operator-specific NAT64 prefix (a network-specific prefix, RFC 6052, announced
54
+ * by the local DNS64) is ordinary global unicast here, so a private IPv4 address reached through
55
+ * it classifies as public. A worker on such a network resolves through a resolver it trusts or adds
56
+ * the prefix to its own deny list.
57
+ */
58
+ export declare const ADDRESS_CLASS_RANGES: readonly AddressClassRange[];
59
+ /**
60
+ * Classifies one IPv4 or IPv6 address literal by {@link ADDRESS_CLASS_RANGES}. IPv6 may carry a
61
+ * zone (`fe80::1%en0`) and a trailing dotted IPv4 address; an IPv6 form that embeds an IPv4 address
62
+ * (v4-mapped and the others in the table) classifies as that IPv4 address, except NAT64. Throws on a
63
+ * string that is not an IP address: brackets, ports, short, octal or hex IPv4 forms, and an IPv4
64
+ * address with a zone.
65
+ */
66
+ export declare function classifyAddress(ip: string): AddressClass;
67
+ /**
68
+ * Every address closed in `open-public` mode as one CIDR list (IPv4, then IPv6), computed from
69
+ * {@link ADDRESS_CLASS_RANGES}: for a consumer that can only deny ranges (the macOS runtime's
70
+ * resolved-address deny list). Embedded forms are expanded (the v4-mapped, SIIT, v4-compatible and
71
+ * 6to4 sub-ranges of every closed IPv4 range), and adjacent closed blocks are merged. An address
72
+ * is in a listed CIDR exactly when {@link classifyAddress} gives it a closed class.
73
+ */
74
+ export declare const OPEN_PUBLIC_DENIED_CIDRS: readonly string[];
75
+ /**
76
+ * Encrypted DNS for a network whose resolver answers with fake IPs (maintainer decision
77
+ * 2026-11-19): a router running a fake-IP proxy (OpenClash and the like) intercepts every port-53
78
+ * query and answers each name with an address in {@link fakeIpCidr} (`198.18.0.0/15`, a reserved
79
+ * class), so in open mode every name would resolve to a closed address. When the system
80
+ * resolver's answer for a name contains such an address, a sandbox egress proxy re-resolves the
81
+ * name (A and AAAA) through DNS-over-HTTPS (RFC 8484, GET, wire format) at these IP-literal
82
+ * endpoints, in order (Cloudflare, then Google as the fallback), verifying TLS against the
83
+ * endpoint's IP SAN so no DNS is needed to reach them. {@link timeoutMs} is one overall deadline
84
+ * per name, covering A and AAAA and every endpoint; each endpoint gets its share of the time left.
85
+ * An answer is cached only when both queries succeeded, for its TTL, at most
86
+ * {@link cacheTtlCapSeconds}, and for at most {@link cacheMaxNames} names. The real address is
87
+ * classified like any resolved address and dialled as checked. When encrypted DNS fails the
88
+ * connection is refused, naming the fake-IP resolver; the fake address is never dialled. The same
89
+ * rule applies to an allowlisted name. Shared by the macOS worker and the Linux forwarder, so both
90
+ * keep identical endpoints and limits.
91
+ */
92
+ export declare const SANDBOX_FAKE_IP_DNS: {
93
+ readonly fakeIpCidr: string;
94
+ readonly endpoints: readonly string[];
95
+ readonly timeoutMs: number;
96
+ readonly cacheTtlCapSeconds: number;
97
+ readonly cacheMaxNames: number;
98
+ };