@agentorg/cli 0.0.5 → 0.0.6

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 (206) hide show
  1. package/README.md +18 -102
  2. package/dist/node_modules/@agentorg/hub/dist/src/hub-actor.d.ts +2 -7
  3. package/dist/node_modules/@agentorg/hub/dist/src/hub-actor.js +4 -144
  4. package/dist/node_modules/@agentorg/hub/dist/src/index.d.ts +1 -3
  5. package/dist/node_modules/@agentorg/hub/dist/src/index.js +1 -3
  6. package/dist/node_modules/@agentorg/hub/dist/src/router.d.ts +6 -57
  7. package/dist/node_modules/@agentorg/hub/dist/src/router.js +38 -413
  8. package/dist/node_modules/@agentorg/hub/dist/src/state.d.ts +17 -317
  9. package/dist/node_modules/@agentorg/hub/dist/src/state.js +42 -536
  10. package/dist/node_modules/@agentorg/hub/dist/src/validate.d.ts +1 -3
  11. package/dist/node_modules/@agentorg/hub/dist/src/validate.js +3 -15
  12. package/dist/node_modules/@agentorg/hub/package.json +0 -3
  13. package/dist/node_modules/@agentorg/interfaces/dist/src/agent-provider.d.ts +132 -0
  14. package/dist/node_modules/@agentorg/interfaces/dist/src/agent-provider.js +105 -0
  15. package/dist/node_modules/@agentorg/interfaces/dist/src/agent-settings.d.ts +42 -0
  16. package/dist/node_modules/@agentorg/interfaces/dist/src/agent-settings.js +53 -0
  17. package/dist/node_modules/@agentorg/interfaces/dist/src/chat.d.ts +15 -0
  18. package/dist/node_modules/@agentorg/interfaces/dist/src/chat.js +14 -0
  19. package/dist/node_modules/@agentorg/interfaces/dist/src/hub.d.ts +16 -286
  20. package/dist/node_modules/@agentorg/interfaces/dist/src/hub.js +17 -159
  21. package/dist/node_modules/@agentorg/interfaces/dist/src/index.d.ts +6 -8
  22. package/dist/node_modules/@agentorg/interfaces/dist/src/index.js +6 -8
  23. package/dist/node_modules/@agentorg/interfaces/dist/src/kv.d.ts +2 -2
  24. package/dist/node_modules/@agentorg/interfaces/dist/src/kv.js +2 -2
  25. package/dist/node_modules/@agentorg/interfaces/dist/src/manager.d.ts +272 -0
  26. package/dist/node_modules/@agentorg/interfaces/dist/src/manager.js +185 -0
  27. package/dist/node_modules/@agentorg/interfaces/dist/src/mcp-provider.d.ts +88 -0
  28. package/dist/node_modules/@agentorg/interfaces/dist/src/mcp-provider.js +78 -0
  29. package/dist/node_modules/@agentorg/interfaces/dist/src/tools.d.ts +39 -0
  30. package/dist/node_modules/@agentorg/interfaces/dist/src/tools.js +43 -0
  31. package/dist/node_modules/@agentorg/manager/dist/src/index.d.ts +1 -0
  32. package/dist/node_modules/@agentorg/manager/dist/src/index.js +1 -0
  33. package/dist/node_modules/@agentorg/manager/dist/src/manager.d.ts +21 -0
  34. package/dist/node_modules/@agentorg/manager/dist/src/manager.js +528 -0
  35. package/dist/node_modules/@agentorg/manager/dist/src/skills.d.ts +25 -0
  36. package/dist/node_modules/@agentorg/manager/dist/src/skills.js +145 -0
  37. package/dist/node_modules/@agentorg/manager/package.json +30 -0
  38. package/dist/node_modules/@agentorg/mcp/dist/src/connection.d.ts +33 -0
  39. package/dist/node_modules/@agentorg/mcp/dist/src/connection.js +290 -0
  40. package/dist/node_modules/@agentorg/mcp/dist/src/index.d.ts +1 -0
  41. package/dist/node_modules/@agentorg/mcp/dist/src/index.js +1 -0
  42. package/dist/node_modules/@agentorg/mcp/dist/src/kinds.d.ts +50 -0
  43. package/dist/node_modules/@agentorg/mcp/dist/src/kinds.js +69 -0
  44. package/dist/node_modules/@agentorg/mcp/dist/src/provider.d.ts +22 -0
  45. package/dist/node_modules/@agentorg/mcp/dist/src/provider.js +167 -0
  46. package/dist/node_modules/@agentorg/mcp/package.json +31 -0
  47. package/dist/node_modules/@agentorg/sdk/dist/src/cli.js +3 -23
  48. package/dist/node_modules/@agentorg/sdk/dist/src/client.d.ts +4 -25
  49. package/dist/node_modules/@agentorg/sdk/dist/src/client.js +5 -55
  50. package/dist/node_modules/@agentorg/sdk/dist/src/errors.d.ts +1 -1
  51. package/dist/node_modules/@agentorg/sdk/dist/src/errors.js +3 -3
  52. package/dist/node_modules/@agentorg/sdk/dist/src/index.d.ts +2 -2
  53. package/dist/node_modules/@agentorg/sdk/dist/src/index.js +1 -1
  54. package/dist/node_modules/@agentorg/sdk/dist/src/interface.d.ts +6 -34
  55. package/dist/node_modules/@agentorg/sdk/dist/src/interface.js +3 -24
  56. package/dist/node_modules/@agentorg/sdk/dist/src/module-host.d.ts +8 -17
  57. package/dist/node_modules/@agentorg/sdk/dist/src/module-host.js +15 -87
  58. package/dist/node_modules/@agentorg/sdk/dist/src/module.d.ts +10 -76
  59. package/dist/node_modules/@agentorg/sdk/dist/src/module.js +3 -23
  60. package/dist/node_modules/@agentorg/sdk/dist/src/person-commands.js +0 -5
  61. package/dist/node_modules/@agentorg/sdk/dist/src/runtime.d.ts +3 -27
  62. package/dist/node_modules/@agentorg/sdk/dist/src/runtime.js +5 -100
  63. package/dist/node_modules/@agentorg/sdk/dist/src/testing.d.ts +7 -8
  64. package/dist/node_modules/@agentorg/sdk/dist/src/testing.js +12 -24
  65. package/dist/node_modules/@agentorg/sdk/package.json +4 -37
  66. package/dist/node_modules/@agentorg/shell/dist/app.css +3435 -739
  67. package/dist/node_modules/@agentorg/shell/dist/app.js +204 -202
  68. package/dist/node_modules/@agentorg/shell/package.json +18 -10
  69. package/dist/node_modules/@agentorg/wire/dist/src/frames.d.ts +2 -3
  70. package/dist/node_modules/@agentorg/wire/dist/src/frames.js +2 -3
  71. package/dist/node_modules/@agentorg/wire/dist/src/ops.d.ts +5 -34
  72. package/dist/node_modules/@agentorg/wire/dist/src/ops.js +2 -17
  73. package/dist/node_modules/assistant/dist/src/agent.d.ts +62 -0
  74. package/dist/node_modules/assistant/dist/src/agent.js +226 -0
  75. package/dist/node_modules/assistant/dist/src/engine.d.ts +23 -0
  76. package/dist/node_modules/assistant/dist/src/engine.js +88 -0
  77. package/dist/node_modules/assistant/dist/src/history.d.ts +97 -0
  78. package/dist/node_modules/assistant/dist/src/history.js +235 -0
  79. package/dist/node_modules/assistant/dist/src/local-store.d.ts +3 -0
  80. package/dist/node_modules/assistant/dist/src/local-store.js +58 -0
  81. package/dist/node_modules/assistant/dist/src/provider.d.ts +21 -0
  82. package/dist/node_modules/assistant/dist/src/provider.js +231 -0
  83. package/dist/node_modules/assistant/dist/src/settings.d.ts +17 -0
  84. package/dist/node_modules/assistant/dist/src/settings.js +43 -0
  85. package/dist/node_modules/assistant/dist/src/tools.d.ts +74 -0
  86. package/dist/node_modules/assistant/dist/src/tools.js +123 -0
  87. package/dist/node_modules/assistant/package.json +29 -0
  88. package/dist/node_modules/chatgpt/dist/src/account.d.ts +52 -0
  89. package/dist/node_modules/chatgpt/dist/src/account.js +270 -0
  90. package/dist/node_modules/chatgpt/dist/src/encoding.d.ts +7 -0
  91. package/dist/node_modules/chatgpt/dist/src/encoding.js +20 -0
  92. package/dist/node_modules/chatgpt/dist/src/file-store.d.ts +9 -0
  93. package/dist/node_modules/chatgpt/dist/src/file-store.js +68 -0
  94. package/dist/node_modules/chatgpt/dist/src/index.d.ts +1 -0
  95. package/dist/node_modules/chatgpt/dist/src/index.js +1 -0
  96. package/dist/node_modules/chatgpt/dist/src/jwt.d.ts +15 -0
  97. package/dist/node_modules/chatgpt/dist/src/jwt.js +37 -0
  98. package/dist/node_modules/chatgpt/dist/src/oauth.d.ts +43 -0
  99. package/dist/node_modules/chatgpt/dist/src/oauth.js +104 -0
  100. package/dist/node_modules/chatgpt/dist/src/program.d.ts +23 -0
  101. package/dist/node_modules/chatgpt/dist/src/program.js +41 -0
  102. package/dist/node_modules/chatgpt/dist/src/responses.d.ts +54 -0
  103. package/dist/node_modules/chatgpt/dist/src/responses.js +300 -0
  104. package/dist/node_modules/chatgpt/dist/src/serve.d.ts +65 -0
  105. package/dist/node_modules/chatgpt/dist/src/serve.js +46 -0
  106. package/dist/node_modules/chatgpt/package.json +33 -0
  107. package/dist/src/api.d.ts +5 -34
  108. package/dist/src/api.js +6 -68
  109. package/dist/src/cli.js +3 -7
  110. package/dist/src/gateway.d.ts +6 -7
  111. package/dist/src/gateway.js +39 -285
  112. package/dist/src/index.d.ts +4 -5
  113. package/dist/src/index.js +3 -4
  114. package/dist/src/notes.d.ts +11 -0
  115. package/dist/src/notes.js +64 -0
  116. package/dist/src/oauth.d.ts +16 -0
  117. package/dist/src/oauth.js +46 -0
  118. package/dist/src/programs.d.ts +29 -0
  119. package/dist/src/programs.js +171 -0
  120. package/package.json +3 -11
  121. package/dist/bundled/index.json +0 -6
  122. package/dist/bundled/sha256-0e91cc3d0e9762b81abc2427b5496b20f383abcd6fb97d928a8d50e956b54d1f.agentorg +0 -0
  123. package/dist/bundled/sha256-1f64ca62a0209d767d6aa6c4feb50b0653d60f10bebbc301f79bd3a37e0153c1.agentorg +0 -0
  124. package/dist/bundled/sha256-4055f8fddf6b90f3d356543f554b2a9e9a2c4a8827a8774f8f87952dc1692331.agentorg +0 -0
  125. package/dist/bundled/sha256-e356ea3c1899138a8494baf521556831006f38534fa9e92ae873e7e6956c3a46.agentorg +0 -0
  126. package/dist/node_modules/@agentorg/hub/dist/src/build.d.ts +0 -17
  127. package/dist/node_modules/@agentorg/hub/dist/src/build.js +0 -120
  128. package/dist/node_modules/@agentorg/hub/dist/src/logs.d.ts +0 -33
  129. package/dist/node_modules/@agentorg/hub/dist/src/logs.js +0 -162
  130. package/dist/node_modules/@agentorg/hub/dist/src/net.d.ts +0 -41
  131. package/dist/node_modules/@agentorg/hub/dist/src/net.js +0 -265
  132. package/dist/node_modules/@agentorg/hub/dist/src/processes.d.ts +0 -78
  133. package/dist/node_modules/@agentorg/hub/dist/src/processes.js +0 -485
  134. package/dist/node_modules/@agentorg/hub/dist/src/storage.d.ts +0 -38
  135. package/dist/node_modules/@agentorg/hub/dist/src/storage.js +0 -194
  136. package/dist/node_modules/@agentorg/interfaces/dist/src/http-egress.d.ts +0 -6
  137. package/dist/node_modules/@agentorg/interfaces/dist/src/http-egress.js +0 -7
  138. package/dist/node_modules/@agentorg/interfaces/dist/src/installer.d.ts +0 -191
  139. package/dist/node_modules/@agentorg/interfaces/dist/src/installer.js +0 -136
  140. package/dist/node_modules/@agentorg/interfaces/dist/src/layout.d.ts +0 -47
  141. package/dist/node_modules/@agentorg/interfaces/dist/src/layout.js +0 -52
  142. package/dist/node_modules/@agentorg/interfaces/dist/src/rules.d.ts +0 -35
  143. package/dist/node_modules/@agentorg/interfaces/dist/src/rules.js +0 -37
  144. package/dist/node_modules/@agentorg/interfaces/dist/src/storage-admin.d.ts +0 -23
  145. package/dist/node_modules/@agentorg/interfaces/dist/src/storage-admin.js +0 -31
  146. package/dist/node_modules/@agentorg/interfaces/dist/src/ui-shell.d.ts +0 -14
  147. package/dist/node_modules/@agentorg/interfaces/dist/src/ui-shell.js +0 -26
  148. package/dist/node_modules/@agentorg/interfaces/dist/src/ui-view.d.ts +0 -27
  149. package/dist/node_modules/@agentorg/interfaces/dist/src/ui-view.js +0 -26
  150. package/dist/node_modules/@agentorg/kit/dist/src/chat.d.ts +0 -37
  151. package/dist/node_modules/@agentorg/kit/dist/src/chat.js +0 -131
  152. package/dist/node_modules/@agentorg/kit/dist/src/components.d.ts +0 -94
  153. package/dist/node_modules/@agentorg/kit/dist/src/components.js +0 -66
  154. package/dist/node_modules/@agentorg/kit/dist/src/icons.d.ts +0 -17
  155. package/dist/node_modules/@agentorg/kit/dist/src/icons.js +0 -30
  156. package/dist/node_modules/@agentorg/kit/dist/src/index.d.ts +0 -6
  157. package/dist/node_modules/@agentorg/kit/dist/src/index.js +0 -10
  158. package/dist/node_modules/@agentorg/kit/dist/src/markdown.d.ts +0 -9
  159. package/dist/node_modules/@agentorg/kit/dist/src/markdown.js +0 -14
  160. package/dist/node_modules/@agentorg/kit/dist/src/resizable.d.ts +0 -5
  161. package/dist/node_modules/@agentorg/kit/dist/src/resizable.js +0 -8
  162. package/dist/node_modules/@agentorg/kit/dist/src/styles.d.ts +0 -11
  163. package/dist/node_modules/@agentorg/kit/dist/src/styles.js +0 -166
  164. package/dist/node_modules/@agentorg/kit/package.json +0 -44
  165. package/dist/node_modules/@agentorg/sdk/dist/frame/runtime.js +0 -753
  166. package/dist/node_modules/@agentorg/sdk/dist/host/runner.js +0 -21963
  167. package/dist/node_modules/@agentorg/sdk/dist/src/build.d.ts +0 -2
  168. package/dist/node_modules/@agentorg/sdk/dist/src/build.js +0 -2
  169. package/dist/node_modules/@agentorg/sdk/dist/src/client-http.d.ts +0 -24
  170. package/dist/node_modules/@agentorg/sdk/dist/src/client-http.js +0 -247
  171. package/dist/node_modules/@agentorg/sdk/dist/src/describe.d.ts +0 -13
  172. package/dist/node_modules/@agentorg/sdk/dist/src/describe.js +0 -16
  173. package/dist/node_modules/@agentorg/sdk/dist/src/frame-base.d.ts +0 -8
  174. package/dist/node_modules/@agentorg/sdk/dist/src/frame-base.js +0 -64
  175. package/dist/node_modules/@agentorg/sdk/dist/src/frame-entry.d.ts +0 -1
  176. package/dist/node_modules/@agentorg/sdk/dist/src/frame-entry.js +0 -35
  177. package/dist/node_modules/@agentorg/sdk/dist/src/frame-host.d.ts +0 -57
  178. package/dist/node_modules/@agentorg/sdk/dist/src/frame-host.js +0 -293
  179. package/dist/node_modules/@agentorg/sdk/dist/src/frame-protocol.d.ts +0 -124
  180. package/dist/node_modules/@agentorg/sdk/dist/src/frame-protocol.js +0 -16
  181. package/dist/node_modules/@agentorg/sdk/dist/src/frame.d.ts +0 -25
  182. package/dist/node_modules/@agentorg/sdk/dist/src/frame.js +0 -248
  183. package/dist/node_modules/@agentorg/sdk/dist/src/host-main.d.ts +0 -1
  184. package/dist/node_modules/@agentorg/sdk/dist/src/host-main.js +0 -60
  185. package/dist/node_modules/@agentorg/sdk/dist/src/host.d.ts +0 -25
  186. package/dist/node_modules/@agentorg/sdk/dist/src/host.js +0 -92
  187. package/dist/node_modules/@agentorg/sdk/dist/src/manifest-api.d.ts +0 -2
  188. package/dist/node_modules/@agentorg/sdk/dist/src/manifest-api.js +0 -2
  189. package/dist/node_modules/@agentorg/sdk/dist/src/manifest.d.ts +0 -56
  190. package/dist/node_modules/@agentorg/sdk/dist/src/manifest.js +0 -165
  191. package/dist/node_modules/@agentorg/sdk/dist/src/package.d.ts +0 -60
  192. package/dist/node_modules/@agentorg/sdk/dist/src/package.js +0 -538
  193. package/dist/node_modules/@agentorg/sdk/dist/src/tar.d.ts +0 -7
  194. package/dist/node_modules/@agentorg/sdk/dist/src/tar.js +0 -71
  195. package/dist/node_modules/@agentorg/shell/dist/agent-bindings.js +0 -59
  196. package/dist/node_modules/@agentorg/shell/src/agent-bindings.ts +0 -107
  197. package/dist/src/frames.d.ts +0 -23
  198. package/dist/src/frames.js +0 -78
  199. package/dist/src/layout.d.ts +0 -44
  200. package/dist/src/layout.js +0 -90
  201. package/dist/src/model.d.ts +0 -54
  202. package/dist/src/model.js +0 -299
  203. package/dist/src/rules.d.ts +0 -71
  204. package/dist/src/rules.js +0 -157
  205. package/dist/src/transfer.d.ts +0 -30
  206. package/dist/src/transfer.js +0 -110
@@ -1,41 +0,0 @@
1
- import type { LookupAddress } from "node:dns";
2
- import { BlockList } from "node:net";
3
- import { type HubState } from "./state.js";
4
- export interface NetOptions {
5
- /** Resolve a host name to every address it has. Tests give their own. */
6
- lookup?: (host: string) => Promise<LookupAddress[]>;
7
- /** A CA to trust beside the usual roots. Tests give their own. */
8
- ca?: string;
9
- /** How long a request may go without a byte either way. */
10
- idleMs?: number;
11
- /** Addresses refused: by default `blockedAddresses()`. Tests leave loopback out to reach their server. */
12
- blocked?: BlockList;
13
- }
14
- /**
15
- * Addresses that aren't the public internet: unspecified, loopback, private (RFC 1918, ULA),
16
- * shared (CGNAT), link-local (the cloud metadata address among them), multicast, and the reserved
17
- * and documentation ranges; in IPv6 also the IPv4-compatible range, Teredo and NAT64's local-use
18
- * prefix. An IPv4-mapped IPv6 address is checked by its IPv4 rules here; `isPublicAddress` checks
19
- * the other forms that carry an IPv4 address. Only tests leave IPv4 loopback out.
20
- */
21
- export declare function blockedAddresses(options?: {
22
- loopback?: boolean;
23
- }): BlockList;
24
- /** Whether `net` may connect to an address: an IP address, not blocked, and carrying none that is. */
25
- export declare function isPublicAddress(address: string, blocked?: BlockList): boolean;
26
- /**
27
- * The built-in `net` Actor's `http.egress@1`: a consumer's request, made from the Hub's process to
28
- * the public internet over HTTPS. The host is resolved and every address checked; the connection
29
- * goes to the checked address (with the name for SNI and the certificate), so a second resolution
30
- * can't move it. Redirects come back as they are. Each request's method, host and status are
31
- * audited; bodies never are.
32
- */
33
- export declare class Net {
34
- #private;
35
- constructor(state: HubState, options?: NetOptions);
36
- /** One request, for the consumer's slot. Refusals and failures throw the SDK's errors. */
37
- handle(request: Request, by: {
38
- consumer: string;
39
- slot: string;
40
- }): Promise<Response>;
41
- }
@@ -1,265 +0,0 @@
1
- import { lookup as dnsLookup } from "node:dns/promises";
2
- import { request as httpsRequest } from "node:https";
3
- import { BlockList, isIP } from "node:net";
4
- import { Readable } from "node:stream";
5
- import { pipeline } from "node:stream/promises";
6
- import { rootCertificates } from "node:tls";
7
- import { OutcomeUnknown, Refused } from "@agentorg/sdk";
8
- import { ERROR_HEADER } from "@agentorg/sdk/http";
9
- import { NET } from "./state.js";
10
- /**
11
- * Addresses that aren't the public internet: unspecified, loopback, private (RFC 1918, ULA),
12
- * shared (CGNAT), link-local (the cloud metadata address among them), multicast, and the reserved
13
- * and documentation ranges; in IPv6 also the IPv4-compatible range, Teredo and NAT64's local-use
14
- * prefix. An IPv4-mapped IPv6 address is checked by its IPv4 rules here; `isPublicAddress` checks
15
- * the other forms that carry an IPv4 address. Only tests leave IPv4 loopback out.
16
- */
17
- export function blockedAddresses(options = {}) {
18
- const blocked = new BlockList();
19
- for (const [network, prefix] of [
20
- ["0.0.0.0", 8],
21
- ["10.0.0.0", 8],
22
- ["100.64.0.0", 10],
23
- ["127.0.0.0", 8],
24
- ["169.254.0.0", 16],
25
- ["172.16.0.0", 12],
26
- ["192.0.0.0", 24],
27
- ["192.0.2.0", 24],
28
- ["192.168.0.0", 16],
29
- ["198.18.0.0", 15],
30
- ["198.51.100.0", 24],
31
- ["203.0.113.0", 24],
32
- ["224.0.0.0", 4],
33
- ["240.0.0.0", 4],
34
- ])
35
- if (options.loopback !== false || network !== "127.0.0.0")
36
- blocked.addSubnet(network, prefix, "ipv4");
37
- for (const [network, prefix] of [
38
- // IPv4-compatible (deprecated), with :: and ::1 in it.
39
- ["::", 96],
40
- ["64:ff9b:1::", 48],
41
- ["100::", 64],
42
- ["2001::", 32],
43
- ["2001:db8::", 32],
44
- ["fc00::", 7],
45
- ["fe80::", 10],
46
- ["fec0::", 10],
47
- ["ff00::", 8],
48
- ])
49
- blocked.addSubnet(network, prefix, "ipv6");
50
- return blocked;
51
- }
52
- /** An IPv6 address's eight 16-bit groups; a zone and a dotted IPv4 tail are understood. */
53
- function groupsOf(address) {
54
- let text = address.toLowerCase().split("%")[0] ?? "";
55
- const dotted = /(\d+)\.(\d+)\.(\d+)\.(\d+)$/.exec(text);
56
- if (dotted) {
57
- const [a, b, c, d] = dotted.slice(1).map(Number);
58
- text = `${text.slice(0, dotted.index)}${((a << 8) | b).toString(16)}:${((c << 8) | d).toString(16)}`;
59
- }
60
- const [head = "", tail] = text.split("::");
61
- const left = head ? head.split(":") : [];
62
- const right = tail ? tail.split(":") : [];
63
- const fill = tail === undefined ? 0 : 8 - left.length - right.length;
64
- const groups = [...left, ...Array(Math.max(fill, 0)).fill("0"), ...right];
65
- return groups.length === 8 ? groups.map((group) => Number.parseInt(group, 16)) : undefined;
66
- }
67
- /**
68
- * The IPv4 address an IPv6 address carries, in the forms that reach it: NAT64's well-known
69
- * prefix (64:ff9b::/96), IPv4-translated (::ffff:0:0:0/96) and 6to4 (2002::/16).
70
- */
71
- function carriedIPv4(address) {
72
- const g = groupsOf(address);
73
- if (!g)
74
- return undefined;
75
- const v4 = (high, low) => `${high >> 8}.${high & 255}.${low >> 8}.${low & 255}`;
76
- const zero = (from, to) => g.slice(from, to).every((x) => x === 0);
77
- if (g[0] === 0x64 && g[1] === 0xff9b && zero(2, 6))
78
- return v4(g[6] ?? 0, g[7] ?? 0);
79
- if (zero(0, 4) && g[4] === 0xffff && g[5] === 0)
80
- return v4(g[6] ?? 0, g[7] ?? 0);
81
- if (g[0] === 0x2002)
82
- return v4(g[1] ?? 0, g[2] ?? 0);
83
- return undefined;
84
- }
85
- /** Whether `net` may connect to an address: an IP address, not blocked, and carrying none that is. */
86
- export function isPublicAddress(address, blocked = blockedAddresses()) {
87
- const family = isIP(address);
88
- if (family === 0)
89
- return false;
90
- if (blocked.check(address, family === 6 ? "ipv6" : "ipv4"))
91
- return false;
92
- const carried = family === 6 ? carriedIPv4(address) : undefined;
93
- return !carried || !blocked.check(carried, "ipv4");
94
- }
95
- /** Headers that describe one hop, not the message. */
96
- const HOP = new Set([
97
- "connection",
98
- "keep-alive",
99
- "transfer-encoding",
100
- "te",
101
- "trailer",
102
- "upgrade",
103
- "proxy-authenticate",
104
- "proxy-authorization",
105
- "proxy-connection",
106
- "host",
107
- ]);
108
- /**
109
- * An upstream response's headers for the consumer: hop-by-hop ones dropped, and the SDK's error
110
- * header too, so no server out there can make the consumer's fetch throw.
111
- */
112
- function responseHeaders(raw) {
113
- const headers = new Headers();
114
- for (const [name, value] of Object.entries(raw)) {
115
- const lower = name.toLowerCase();
116
- if (HOP.has(lower) || lower === ERROR_HEADER)
117
- continue;
118
- if (Array.isArray(value))
119
- for (const one of value)
120
- headers.append(name, one);
121
- else if (value !== undefined)
122
- headers.set(name, value);
123
- }
124
- return headers;
125
- }
126
- /**
127
- * The built-in `net` Actor's `http.egress@1`: a consumer's request, made from the Hub's process to
128
- * the public internet over HTTPS. The host is resolved and every address checked; the connection
129
- * goes to the checked address (with the name for SNI and the certificate), so a second resolution
130
- * can't move it. Redirects come back as they are. Each request's method, host and status are
131
- * audited; bodies never are.
132
- */
133
- export class Net {
134
- #state;
135
- #lookup;
136
- #ca;
137
- #idleMs;
138
- #blocked;
139
- constructor(state, options = {}) {
140
- this.#state = state;
141
- this.#lookup = options.lookup ?? ((host) => dnsLookup(host, { all: true, verbatim: true }));
142
- this.#ca = options.ca ? [...rootCertificates, options.ca] : undefined;
143
- this.#idleMs = options.idleMs ?? 5 * 60_000;
144
- this.#blocked = options.blocked ?? blockedAddresses();
145
- }
146
- /** One request, for the consumer's slot. Refusals and failures throw the SDK's errors. */
147
- async handle(request, by) {
148
- const url = new URL(request.url);
149
- const audit = (outcome) => {
150
- try {
151
- this.#state.auditHub("net.request", { ...by, method: request.method, host: url.host, ...outcome }, NET);
152
- }
153
- catch {
154
- // The state is closed: the Hub is shutting down.
155
- }
156
- };
157
- try {
158
- const response = await this.#send(request, url);
159
- audit({ status: response.status });
160
- return response;
161
- }
162
- catch (error) {
163
- audit({ error: error instanceof Refused ? error.code : error.name });
164
- throw error;
165
- }
166
- }
167
- async #send(request, url) {
168
- if (url.protocol !== "https:")
169
- throw new Refused("forbidden", `net reaches only https: URLs, not ${url.protocol}.`);
170
- const host = url.hostname.replace(/^\[|\]$/g, "");
171
- let addresses;
172
- if (isIP(host))
173
- addresses = [{ address: host, family: isIP(host) }];
174
- else
175
- try {
176
- addresses = await this.#lookup(host);
177
- }
178
- catch {
179
- throw new Refused("unreachable", `${host} doesn't resolve.`);
180
- }
181
- if (!addresses.length)
182
- throw new Refused("unreachable", `${host} doesn't resolve.`);
183
- for (const { address } of addresses)
184
- if (!isPublicAddress(address, this.#blocked))
185
- throw new Refused("forbidden", `${host} is at ${address}, which isn't on the public internet.`);
186
- const target = addresses[0];
187
- const sendsBody = Boolean(request.body) && request.method !== "GET" && request.method !== "HEAD";
188
- const headers = {};
189
- request.headers.forEach((value, name) => {
190
- if (HOP.has(name) || name === "set-cookie")
191
- return;
192
- // The length comes from the body net sends, which is none for GET and HEAD.
193
- if (name === "content-length" || name === "expect")
194
- return;
195
- headers[name] = value;
196
- });
197
- headers.host = url.host;
198
- return new Promise((resolve, reject) => {
199
- /** Whether anything may have reached the server: from the TLS handshake on. */
200
- let connected = false;
201
- const options = {
202
- host,
203
- port: Number(url.port || 443),
204
- path: `${url.pathname}${url.search}`,
205
- method: request.method,
206
- headers,
207
- agent: false,
208
- ...(this.#ca ? { ca: this.#ca } : {}),
209
- // Every address was checked: the connection goes to one of them (node falls back between
210
- // them), never to a new lookup.
211
- lookup: (_name, options, callback) => {
212
- if (options.all)
213
- callback(null, addresses);
214
- else
215
- callback(null, target.address, target.family);
216
- },
217
- };
218
- const outgoing = httpsRequest(options, (incoming) => {
219
- const status = incoming.statusCode ?? 0;
220
- // Whatever a server out there answers, it ends as a response or an error, never a throw
221
- // in this process.
222
- try {
223
- if (status < 200 || status > 599)
224
- throw new Error(`a status of ${status}`);
225
- const empty = request.method === "HEAD" || status === 204 || status === 205 || status === 304;
226
- const response = new Response(empty ? null : Readable.toWeb(incoming), {
227
- status,
228
- statusText: incoming.statusMessage ?? "",
229
- headers: responseHeaders(incoming.headers),
230
- });
231
- if (empty)
232
- incoming.resume();
233
- resolve(response);
234
- }
235
- catch (error) {
236
- incoming.destroy();
237
- reject(new OutcomeUnknown(`${url.host} answered what isn't an HTTP response net passes on: ${error.message}`));
238
- }
239
- });
240
- // An upgrade nobody asked for: the request had reached the server.
241
- outgoing.on("upgrade", (_response, socket) => {
242
- socket.destroy();
243
- reject(new OutcomeUnknown(`${url.host} switched protocols, which net doesn't follow.`));
244
- });
245
- outgoing.on("socket", (socket) => socket.once("secureConnect", () => (connected = true)));
246
- // Before the TLS handshake is done nothing has been sent, so a quiet server is unreachable.
247
- outgoing.setTimeout(this.#idleMs, () => outgoing.destroy(connected
248
- ? new OutcomeUnknown(`${url.host} sent nothing for ${this.#idleMs / 1000} s.`)
249
- : new Refused("unreachable", `${url.host} didn't finish connecting within ${this.#idleMs / 1000} s.`)));
250
- outgoing.on("error", (error) => reject(error instanceof OutcomeUnknown || error instanceof Refused
251
- ? error
252
- : connected
253
- ? new OutcomeUnknown(`The request to ${url.host} failed: ${error.message}`)
254
- : new Refused("unreachable", `${url.host} couldn't be reached: ${error.message}`)));
255
- const abort = () => outgoing.destroy(request.signal.reason ?? new Error("aborted"));
256
- if (request.signal.aborted)
257
- return abort();
258
- request.signal.addEventListener("abort", abort, { once: true });
259
- outgoing.once("close", () => request.signal.removeEventListener("abort", abort));
260
- if (!sendsBody || !request.body)
261
- return void outgoing.end();
262
- pipeline(Readable.fromWeb(request.body), outgoing).catch((error) => outgoing.destroy(error));
263
- });
264
- }
265
- }
@@ -1,78 +0,0 @@
1
- import type { Duplex } from "@agentorg/sdk";
2
- import type { ChannelHandle } from "./router.js";
3
- import type { HubState } from "./state.js";
4
- /** Whether this machine can run host processes now, and if not, why and what to do. */
5
- export interface HostStatus {
6
- available: boolean;
7
- reason?: string;
8
- }
9
- export interface ProcessOptions {
10
- /**
11
- * The sandbox a host process runs in: the command and arguments put before `node …`. By default,
12
- * `sandbox-exec` on macOS and `unshare` on Linux; tests may give another (one that fails, say).
13
- */
14
- sandbox?: string[];
15
- /** Heap limit of each process, in MB. */
16
- memoryMb?: number;
17
- /** How long a process has to say hello. */
18
- helloMs?: number;
19
- /** How long `stop` waits after SIGTERM before SIGKILL. */
20
- stopMs?: number;
21
- /** The first restart's delay after a crash; each next one doubles, up to `maxBackoffMs`. */
22
- backoffMs?: number;
23
- maxBackoffMs?: number;
24
- /** Up this long, a process's next crash starts the backoff over. */
25
- resetAfterMs?: number;
26
- }
27
- /**
28
- * The sandbox command for a process that may read `paths`: on macOS, sandbox-exec with the
29
- * profile; on Linux, a user, network, PID and mount namespace (no network or DNS, no other process
30
- * to signal) with the minimal root above, built on `rootDir`. Root inside the namespace is nobody
31
- * outside it (--map-root-user: util-linux before 2.38 lacks --map-current-user).
32
- */
33
- export declare function defaultSandbox(rootDir: string, paths: string[]): string[] | undefined;
34
- /**
35
- * This user's root folder for the Linux sandbox, made if missing (0700). Only one that is a real
36
- * folder, owned by this user and closed to others, is used: another user could make the path
37
- * first.
38
- */
39
- export declare function rootFolder(): {
40
- path: string;
41
- } | {
42
- problem: string;
43
- };
44
- /**
45
- * The Hub's host processes: one per running package Actor, spawned under Node's permission model
46
- * inside the OS sandbox, with an empty environment and the channel on fd 3. A process that exits
47
- * without `stop` asking is a crash: it is restarted after a backoff while its Actor is `running`.
48
- */
49
- export declare class Processes {
50
- #private;
51
- constructor(state: HubState, accept: (channel: Duplex, admitted: {
52
- actorId: string;
53
- }) => ChannelHandle, options?: ProcessOptions);
54
- /** The last probe's answer; none before the first. */
55
- get status(): HostStatus | undefined;
56
- /**
57
- * Run the sandbox once, around `node -e 0`, and keep what it says. A change is audited, and once
58
- * the host is available, Actors recorded as `running` without a process are started.
59
- */
60
- /** The sandbox command for a process that may read `paths`; none where there is no sandbox. */
61
- /**
62
- * The OS sandbox command for a process that may read `paths`, as host processes run: for the
63
- * Hub's build too, which runs untrusted source to read its modules' definitions.
64
- */
65
- sandboxCommand(paths: string[]): string[] | undefined;
66
- probe(): Promise<HostStatus>;
67
- /**
68
- * Spawn an Actor's process, unless it has one (or one restarting). One still stopping is let go
69
- * first; then a process is spawned if the Actor is still `running`.
70
- */
71
- start(actorId: string): void;
72
- /** Stop an Actor's process: SIGTERM, then SIGKILL after the grace; a waiting restart is dropped. */
73
- stop(actorId: string): Promise<void>;
74
- /** Refused unless host processes can start here: the probe runs again first. */
75
- ready(): Promise<void>;
76
- /** The Hub is closing: every process is killed, stops in flight are settled, nothing restarts. */
77
- close(): void;
78
- }