@agentorg/cli 0.0.4 → 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 -111
  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 +20 -298
  9. package/dist/node_modules/@agentorg/hub/dist/src/state.js +73 -456
  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 -267
  20. package/dist/node_modules/@agentorg/interfaces/dist/src/hub.js +17 -145
  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-01d69bc3888c2a53963f4413d47de909d129ad27c78e9af6d830bb50c3478419.agentorg +0 -0
  123. package/dist/bundled/sha256-84165e3be5c904fc971d983dab31102e07cca725d8629a6fd7d118fa3a0a88b8.agentorg +0 -0
  124. package/dist/bundled/sha256-ade9132b3f34b4c39db92adeadc7e540dc745e4a81b5b54f5d45bf9ec92bca75.agentorg +0 -0
  125. package/dist/bundled/sha256-f4330f5987f37d8cf3aeb44d2f831b573641a87186daa2f811f0c35ba04804f0.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 -51
  202. package/dist/src/model.js +0 -230
  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,2 +0,0 @@
1
- export { BuildError, type BuildOptions, type Built, buildPackage, verifyPackage, } from "./package.js";
2
- export { writeTar } from "./tar.js";
@@ -1,2 +0,0 @@
1
- export { BuildError, buildPackage, verifyPackage, } from "./package.js";
2
- export { writeTar } from "./tar.js";
@@ -1,24 +0,0 @@
1
- import type { Duplex, Log } from "./module.js";
2
- /**
3
- * The header that carries an SDK error a provider's handler threw, as its error body in JSON, on a
4
- * 502: the consumer's `fetch` throws that error instead of returning the response.
5
- */
6
- export declare const ERROR_HEADER = "agentorg-error";
7
- /**
8
- * Send one request over the stream and read its response. The request line carries the request's
9
- * absolute URL, so the provider sees exactly what was asked for. Aborting the request's signal
10
- * resets the stream; once the response's body has ended, so is the stream, since nothing more is
11
- * read. A provider whose handler threw one of the SDK's errors makes this throw it (`target`
12
- * names the slot in a NotConnected).
13
- */
14
- export declare function fetchOver(stream: Duplex, request: Request, target?: string): Promise<Response>;
15
- /**
16
- * Serve requests arriving on the stream with `handle`, until the stream ends. The handler's
17
- * `request.url` is the consumer's absolute URL, from the request line; a request line that isn't
18
- * absolute, or whose host isn't the `Host` header's, is answered 400. A handler that throws one
19
- * of the SDK's errors before answering reaches the consumer's `fetch` as that error (a 502 with
20
- * the error header); any other throw answers 500 with its message. A body that fails once sent
21
- * ends the response abruptly, so the consumer's read fails rather than looking complete. The
22
- * handler's request is aborted if the consumer goes before the response is done.
23
- */
24
- export declare function serveOver(stream: Duplex, handle: (request: Request) => Promise<Response>, log: Log): Promise<void>;
@@ -1,247 +0,0 @@
1
- import { createServer, request as httpRequest } from "node:http";
2
- import { Duplex as NodeDuplex, Readable } from "node:stream";
3
- import { pipeline } from "node:stream/promises";
4
- import { errorBodyOf, errorFromBody, NotConnected, OutcomeUnknown, Refused, } from "./errors.js";
5
- /**
6
- * The header that carries an SDK error a provider's handler threw, as its error body in JSON, on a
7
- * 502: the consumer's `fetch` throws that error instead of returning the response.
8
- */
9
- export const ERROR_HEADER = "agentorg-error";
10
- const ERROR_NAMES = new Set(["Refused", "NotConnected", "OutcomeUnknown"]);
11
- /** The error a response carries, if it is a 502 whose error header is one of the SDK's three. */
12
- function carriedError(status, header) {
13
- if (status !== 502 || typeof header !== "string")
14
- return undefined;
15
- try {
16
- const body = JSON.parse(header);
17
- if (typeof body !== "object" || body === null || !ERROR_NAMES.has(String(body.name)))
18
- return undefined;
19
- return {
20
- name: body.name,
21
- message: String(body.message ?? ""),
22
- ...(typeof body.code === "string" ? { code: body.code } : {}),
23
- };
24
- }
25
- catch {
26
- return undefined;
27
- }
28
- }
29
- /** JSON with everything past ASCII escaped, so it fits in a header. */
30
- const asciiJson = (value) => JSON.stringify(value).replace(/[\u007f-\uffff]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
31
- /**
32
- * HTTP/1.1 over one of the Hub's byte streams, with `node:http` on both ends, one request per
33
- * stream. `node:http` wants a socket; a stream adapted from the web pair, with the few socket
34
- * methods it calls, serves. Destroying it resets the Hub's stream.
35
- */
36
- function socketOf(stream) {
37
- // Built by hand rather than with Duplex.fromWeb, whose destroy throws on Node 22.
38
- const reader = stream.readable.getReader();
39
- const writer = stream.writable.getWriter();
40
- const socket = new NodeDuplex({
41
- read() {
42
- reader.read().then(({ value, done }) => {
43
- this.push(done ? null : value);
44
- }, (error) => this.destroy(error));
45
- },
46
- write(chunk, _encoding, callback) {
47
- writer.write(chunk).then(() => callback(), callback);
48
- },
49
- final(callback) {
50
- writer.close().then(() => callback(), callback);
51
- },
52
- destroy(error, callback) {
53
- // Either half going resets the Hub's stream.
54
- reader.cancel(error ?? undefined).catch(() => { });
55
- writer.abort(error ?? undefined).catch(() => { });
56
- callback(error);
57
- },
58
- });
59
- return Object.assign(socket, {
60
- setTimeout: () => socket,
61
- setNoDelay: () => socket,
62
- setKeepAlive: () => socket,
63
- // node:http ends a finished connection this way: our side closes once its writes are out,
64
- // and the other side, done reading, resets the stream.
65
- destroySoon: () => socket.end(),
66
- remoteAddress: "hub",
67
- });
68
- }
69
- /** Headers that describe one hop, not the message: node:http sets its own on each side. */
70
- const HOP = new Set([
71
- "connection",
72
- "keep-alive",
73
- "transfer-encoding",
74
- "te",
75
- "trailer",
76
- "upgrade",
77
- "proxy-authenticate",
78
- "proxy-authorization",
79
- "proxy-connection",
80
- ]);
81
- function headersOf(raw) {
82
- const headers = new Headers();
83
- for (const [name, value] of Object.entries(raw)) {
84
- if (HOP.has(name))
85
- continue;
86
- if (Array.isArray(value))
87
- for (const one of value)
88
- headers.append(name, one);
89
- else if (value !== undefined)
90
- headers.set(name, value);
91
- }
92
- return headers;
93
- }
94
- /** Headers to send: hop-by-hop ones dropped, each `set-cookie` kept apart. */
95
- function outgoingHeaders(headers) {
96
- const out = {};
97
- headers.forEach((value, name) => {
98
- if (!HOP.has(name) && name !== "set-cookie")
99
- out[name] = value;
100
- });
101
- const cookies = headers.getSetCookie();
102
- if (cookies.length)
103
- out["set-cookie"] = cookies;
104
- return out;
105
- }
106
- const noBody = (method) => method === "GET" || method === "HEAD";
107
- /**
108
- * Send one request over the stream and read its response. The request line carries the request's
109
- * absolute URL, so the provider sees exactly what was asked for. Aborting the request's signal
110
- * resets the stream; once the response's body has ended, so is the stream, since nothing more is
111
- * read. A provider whose handler threw one of the SDK's errors makes this throw it (`target`
112
- * names the slot in a NotConnected).
113
- */
114
- export function fetchOver(stream, request, target = "the http slot") {
115
- const socket = socketOf(stream);
116
- const url = new URL(request.url);
117
- const headers = outgoingHeaders(request.headers);
118
- headers.host = url.host;
119
- headers.connection = "close";
120
- return new Promise((resolve, reject) => {
121
- const outgoing = httpRequest({
122
- // No agent: with createConnection, node:http uses this stream and pools nothing.
123
- createConnection: () => socket,
124
- method: request.method,
125
- path: url.href,
126
- headers,
127
- }, (incoming) => {
128
- const status = incoming.statusCode ?? 502;
129
- const carried = carriedError(status, incoming.headers[ERROR_HEADER]);
130
- if (carried) {
131
- incoming.resume();
132
- socket.destroy();
133
- return reject(errorFromBody(carried, target));
134
- }
135
- const empty = request.method === "HEAD" || status === 204 || status === 205 || status === 304;
136
- // The response is whole: an upload the provider never read stops here.
137
- incoming.once("end", () => socket.destroy());
138
- // Whatever the provider answers, it ends as a response or an error, never a throw here.
139
- try {
140
- if (status < 200 || status > 599)
141
- throw new Error(`a status of ${status}`);
142
- const response = new Response(empty ? null : Readable.toWeb(incoming), {
143
- status,
144
- statusText: incoming.statusMessage ?? "",
145
- headers: headersOf(incoming.headers),
146
- });
147
- if (empty)
148
- incoming.resume();
149
- resolve(response);
150
- }
151
- catch (error) {
152
- socket.destroy();
153
- reject(new OutcomeUnknown(`The provider answered what isn't a response: ${error.message}`));
154
- }
155
- });
156
- const abort = () => {
157
- const reason = request.signal.reason ?? new Error("The request was aborted.");
158
- outgoing.destroy(reason);
159
- socket.destroy();
160
- reject(reason);
161
- };
162
- // Listened for first: node:http settles a request destroyed at once a tick later, with an
163
- // error of its own ("socket hang up"), which would otherwise be thrown at the process.
164
- outgoing.on("error", reject);
165
- if (request.signal.aborted)
166
- return abort();
167
- request.signal.addEventListener("abort", abort, { once: true });
168
- outgoing.once("close", () => request.signal.removeEventListener("abort", abort));
169
- if (!request.body || noBody(request.method))
170
- return void outgoing.end();
171
- pipeline(Readable.fromWeb(request.body), outgoing).catch(() => { });
172
- });
173
- }
174
- /**
175
- * Serve requests arriving on the stream with `handle`, until the stream ends. The handler's
176
- * `request.url` is the consumer's absolute URL, from the request line; a request line that isn't
177
- * absolute, or whose host isn't the `Host` header's, is answered 400. A handler that throws one
178
- * of the SDK's errors before answering reaches the consumer's `fetch` as that error (a 502 with
179
- * the error header); any other throw answers 500 with its message. A body that fails once sent
180
- * ends the response abruptly, so the consumer's read fails rather than looking complete. The
181
- * handler's request is aborted if the consumer goes before the response is done.
182
- */
183
- export function serveOver(stream, handle, log) {
184
- const server = createServer(async (incoming, outgoing) => {
185
- const method = incoming.method ?? "GET";
186
- const left = new AbortController();
187
- outgoing.once("close", () => {
188
- if (!outgoing.writableFinished)
189
- left.abort(new Error("The consumer went away."));
190
- });
191
- let target;
192
- try {
193
- target = new URL(incoming.url ?? "");
194
- }
195
- catch {
196
- target = undefined;
197
- }
198
- if (!target ||
199
- (target.protocol !== "http:" && target.protocol !== "https:") ||
200
- target.host !== incoming.headers.host) {
201
- outgoing.writeHead(400, { "content-type": "text/plain" });
202
- return void outgoing.end("A request names its absolute URL, whose host is the Host header's.");
203
- }
204
- try {
205
- const request = new Request(target.href, {
206
- method,
207
- headers: headersOf(incoming.headers),
208
- signal: left.signal,
209
- ...(noBody(method)
210
- ? {}
211
- : { body: Readable.toWeb(incoming), duplex: "half" }),
212
- });
213
- const response = await handle(request);
214
- outgoing.writeHead(response.status, response.statusText, outgoingHeaders(response.headers));
215
- if (!response.body || method === "HEAD")
216
- return void outgoing.end();
217
- // Paced by the consumer: the next chunk is read once the last one is taken.
218
- await pipeline(Readable.fromWeb(response.body), outgoing);
219
- }
220
- catch (error) {
221
- if (outgoing.headersSent) {
222
- log.error("An http handler failed.", { error: String(error) });
223
- return void outgoing.destroy(error);
224
- }
225
- if (error instanceof Refused ||
226
- error instanceof NotConnected ||
227
- error instanceof OutcomeUnknown) {
228
- const body = errorBodyOf(error);
229
- body.message = body.message.slice(0, 1024);
230
- outgoing.writeHead(502, {
231
- "content-type": "text/plain",
232
- [ERROR_HEADER]: asciiJson(body),
233
- });
234
- return void outgoing.end(body.message);
235
- }
236
- log.error("An http handler failed.", { error: String(error) });
237
- outgoing.writeHead(500, { "content-type": "text/plain" });
238
- outgoing.end(error instanceof Error ? error.message : String(error));
239
- }
240
- });
241
- const socket = socketOf(stream);
242
- return new Promise((resolve) => {
243
- socket.once("close", () => resolve());
244
- socket.once("error", () => resolve());
245
- server.emit("connection", socket);
246
- });
247
- }
@@ -1,13 +0,0 @@
1
- import { type DescribedInterface } from "./interface.js";
2
- import { type Placement } from "./module.js";
3
- /** A module as the build reads it from its code. */
4
- export interface ModuleDescription {
5
- placement: Placement;
6
- slots: Record<string, DescribedInterface>;
7
- exports: Record<string, DescribedInterface>;
8
- }
9
- /**
10
- * Describe a module's default export. The build bundles this with the author's own module, so it
11
- * uses the same SDK and zod copies as the module, and runs it in a permission-limited process.
12
- */
13
- export declare function describeModule(definition: unknown): ModuleDescription;
@@ -1,16 +0,0 @@
1
- import { describeInterface } from "./interface.js";
2
- import { isModuleDefinition } from "./module.js";
3
- /**
4
- * Describe a module's default export. The build bundles this with the author's own module, so it
5
- * uses the same SDK and zod copies as the module, and runs it in a permission-limited process.
6
- */
7
- export function describeModule(definition) {
8
- if (!isModuleDefinition(definition))
9
- throw new TypeError("The default export isn't a module: define it with defineActor or defineWidget.");
10
- const describe = (interfaces) => Object.fromEntries(Object.entries(interfaces).map(([name, iface]) => [name, describeInterface(iface)]));
11
- return {
12
- placement: definition.placement,
13
- slots: describe(definition.slots),
14
- exports: describe(definition.exports),
15
- };
16
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * The base stylesheet every view's frame gets first, before the view's own: the document fills the
3
- * frame on a transparent background, and plain HTML looks like the shell, drawn with the theme's
4
- * tokens (`--fg`, `--surface`, `--accent`, … as the shell sends them at mount). Every rule is in
5
- * `:where()`, so it has no specificity: any selector a view writes wins, and a view that wants its
6
- * own look draws it.
7
- */
8
- export declare const FRAME_BASE = "\n:where(*, *::before, *::after) { box-sizing: border-box; }\n:where(html, body) { height: 100%; margin: 0; background: transparent; }\n:where(body) {\n overflow: auto; scrollbar-width: none;\n color: var(--fg); font: 14px/1.45 var(--font, ui-sans-serif, system-ui, sans-serif);\n -webkit-font-smoothing: antialiased;\n}\n:where(body)::-webkit-scrollbar { display: none; }\n:where(body > :only-child) { min-height: 100%; }\n:where(h1, h2, h3, h4) { margin: 0 0 8px; font-weight: 600; letter-spacing: -0.01em; }\n:where(h1) { font-size: 20px; }\n:where(h2) { font-size: 16px; }\n:where(h3, h4) { font-size: 14px; }\n:where(p) { margin: 0 0 8px; }\n:where(small) { color: var(--muted); font-size: 12.5px; }\n:where(a) { color: inherit; text-underline-offset: 2px; }\n:where(hr) { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }\n:where(ul, ol) { margin: 0 0 10px; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }\n:where(li) { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--raised); }\n:where(button) {\n height: 34px; padding: 0 12px; border: 0; border-radius: 9px; cursor: pointer;\n background: var(--hover); color: var(--fg); font: inherit; font-weight: 500;\n}\n:where(button:hover) { background: var(--selected); }\n:where(button:disabled) { opacity: 0.5; cursor: default; }\n:where(button[type=\"submit\"], button.primary) { background: var(--accent); color: var(--accent-fg); font-weight: 600; }\n:where(input:not([type]), input[type=\"text\"], input[type=\"search\"], input[type=\"number\"], input[type=\"url\"], input[type=\"email\"], select) {\n height: 34px; padding: 0 10px; border: 0; border-radius: 9px; outline: 0;\n background: var(--raised); color: var(--fg); font: inherit;\n}\n:where(textarea) { padding: 8px 10px; border: 0; border-radius: 9px; outline: 0; resize: none; background: var(--raised); color: var(--fg); font: inherit; }\n:where(input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible) { box-shadow: 0 0 0 1.5px var(--ring); outline: 0; }\n:where(input[type=\"checkbox\"]) {\n appearance: none; width: 16px; height: 16px; margin: 0; flex: none; display: grid; place-items: center;\n border: 1.5px solid var(--faint); border-radius: 5px; cursor: pointer;\n}\n:where(input[type=\"checkbox\"]:checked) { background: var(--ok); border-color: var(--ok); }\n:where(input[type=\"checkbox\"]:checked)::after {\n content: \"\"; width: 4px; height: 8px; border: solid white; border-width: 0 2px 2px 0;\n transform: translateY(-1px) rotate(45deg);\n}\n:where(li:has(> input[type=\"checkbox\"]:checked) > span) { color: var(--faint); text-decoration: line-through; }\n:where(form) { display: flex; gap: 6px; }\n:where(form > input, form > textarea) { flex: 1; min-width: 0; }\n:where(table) { width: 100%; border-collapse: collapse; font-size: 13px; }\n:where(th) { padding: 0 8px 6px; text-align: left; color: var(--faint); font-weight: 500; font-size: 12px; }\n:where(td) { padding: 7px 8px; border-top: 1px solid var(--line); }\n:where(code, pre) { font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }\n:where(code) { padding: 1px 5px; border-radius: 5px; background: var(--raised); }\n:where(pre) { margin: 0 0 10px; padding: 10px 12px; border-radius: 10px; background: var(--raised); overflow: auto; }\n:where(pre code) { padding: 0; background: none; }\n:where(progress) { appearance: none; width: 100%; height: 4px; border: 0; border-radius: 2px; background: var(--raised); }\n:where(progress)::-webkit-progress-bar { background: var(--raised); border-radius: 2px; }\n:where(progress)::-webkit-progress-value { background: var(--ok); border-radius: 2px; }\n:where(progress)::-moz-progress-bar { background: var(--ok); border-radius: 2px; }\n";
@@ -1,64 +0,0 @@
1
- /**
2
- * The base stylesheet every view's frame gets first, before the view's own: the document fills the
3
- * frame on a transparent background, and plain HTML looks like the shell, drawn with the theme's
4
- * tokens (`--fg`, `--surface`, `--accent`, … as the shell sends them at mount). Every rule is in
5
- * `:where()`, so it has no specificity: any selector a view writes wins, and a view that wants its
6
- * own look draws it.
7
- */
8
- export const FRAME_BASE = `
9
- :where(*, *::before, *::after) { box-sizing: border-box; }
10
- :where(html, body) { height: 100%; margin: 0; background: transparent; }
11
- :where(body) {
12
- overflow: auto; scrollbar-width: none;
13
- color: var(--fg); font: 14px/1.45 var(--font, ui-sans-serif, system-ui, sans-serif);
14
- -webkit-font-smoothing: antialiased;
15
- }
16
- :where(body)::-webkit-scrollbar { display: none; }
17
- :where(body > :only-child) { min-height: 100%; }
18
- :where(h1, h2, h3, h4) { margin: 0 0 8px; font-weight: 600; letter-spacing: -0.01em; }
19
- :where(h1) { font-size: 20px; }
20
- :where(h2) { font-size: 16px; }
21
- :where(h3, h4) { font-size: 14px; }
22
- :where(p) { margin: 0 0 8px; }
23
- :where(small) { color: var(--muted); font-size: 12.5px; }
24
- :where(a) { color: inherit; text-underline-offset: 2px; }
25
- :where(hr) { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
26
- :where(ul, ol) { margin: 0 0 10px; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
27
- :where(li) { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--raised); }
28
- :where(button) {
29
- height: 34px; padding: 0 12px; border: 0; border-radius: 9px; cursor: pointer;
30
- background: var(--hover); color: var(--fg); font: inherit; font-weight: 500;
31
- }
32
- :where(button:hover) { background: var(--selected); }
33
- :where(button:disabled) { opacity: 0.5; cursor: default; }
34
- :where(button[type="submit"], button.primary) { background: var(--accent); color: var(--accent-fg); font-weight: 600; }
35
- :where(input:not([type]), input[type="text"], input[type="search"], input[type="number"], input[type="url"], input[type="email"], select) {
36
- height: 34px; padding: 0 10px; border: 0; border-radius: 9px; outline: 0;
37
- background: var(--raised); color: var(--fg); font: inherit;
38
- }
39
- :where(textarea) { padding: 8px 10px; border: 0; border-radius: 9px; outline: 0; resize: none; background: var(--raised); color: var(--fg); font: inherit; }
40
- :where(input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible) { box-shadow: 0 0 0 1.5px var(--ring); outline: 0; }
41
- :where(input[type="checkbox"]) {
42
- appearance: none; width: 16px; height: 16px; margin: 0; flex: none; display: grid; place-items: center;
43
- border: 1.5px solid var(--faint); border-radius: 5px; cursor: pointer;
44
- }
45
- :where(input[type="checkbox"]:checked) { background: var(--ok); border-color: var(--ok); }
46
- :where(input[type="checkbox"]:checked)::after {
47
- content: ""; width: 4px; height: 8px; border: solid white; border-width: 0 2px 2px 0;
48
- transform: translateY(-1px) rotate(45deg);
49
- }
50
- :where(li:has(> input[type="checkbox"]:checked) > span) { color: var(--faint); text-decoration: line-through; }
51
- :where(form) { display: flex; gap: 6px; }
52
- :where(form > input, form > textarea) { flex: 1; min-width: 0; }
53
- :where(table) { width: 100%; border-collapse: collapse; font-size: 13px; }
54
- :where(th) { padding: 0 8px 6px; text-align: left; color: var(--faint); font-weight: 500; font-size: 12px; }
55
- :where(td) { padding: 7px 8px; border-top: 1px solid var(--line); }
56
- :where(code, pre) { font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
57
- :where(code) { padding: 1px 5px; border-radius: 5px; background: var(--raised); }
58
- :where(pre) { margin: 0 0 10px; padding: 10px 12px; border-radius: 10px; background: var(--raised); overflow: auto; }
59
- :where(pre code) { padding: 0; background: none; }
60
- :where(progress) { appearance: none; width: 100%; height: 4px; border: 0; border-radius: 2px; background: var(--raised); }
61
- :where(progress)::-webkit-progress-bar { background: var(--raised); border-radius: 2px; }
62
- :where(progress)::-webkit-progress-value { background: var(--ok); border-radius: 2px; }
63
- :where(progress)::-moz-progress-bar { background: var(--ok); border-radius: 2px; }
64
- `;
@@ -1,35 +0,0 @@
1
- var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
- if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
- return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
- return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
- });
6
- }
7
- return path;
8
- };
9
- import { runFrame } from "./frame.js";
10
- import { FRAME_BASE } from "./frame-base.js";
11
- import { FRAME_HELLO } from "./frame-protocol.js";
12
- const self = globalThis;
13
- let frame;
14
- const base = self.document.createElement("style");
15
- base.textContent = FRAME_BASE;
16
- self.document.head.prepend(base);
17
- self.addEventListener("message", (event) => {
18
- const port = event.ports[0];
19
- if (frame || event.source !== self.parent || event.data !== FRAME_HELLO || !port)
20
- return;
21
- frame = runFrame({
22
- port,
23
- root: self.document.body,
24
- // A computed specifier: the bundler leaves it to the browser.
25
- load: (src) => import(__rewriteRelativeImportExtension(src)),
26
- theme(tokens) {
27
- for (const [name, value] of Object.entries(tokens))
28
- if (name.startsWith("--"))
29
- self.document.documentElement.style.setProperty(name, value);
30
- },
31
- });
32
- });
33
- // What the view doesn't catch goes to its Actor's log.
34
- self.addEventListener("error", (event) => frame?.failed(event.error ?? event.message));
35
- self.addEventListener("unhandledrejection", (event) => frame?.failed(event.reason));
@@ -1,57 +0,0 @@
1
- import { type PortLike } from "./frame-protocol.js";
2
- /** Where a frame's requests go: its slots, run as the view's Actor, and the shell itself. */
3
- export interface FrameHandlers {
4
- /** A call on one of the view's slots. */
5
- call(slot: string, method: string, input: unknown): Promise<unknown>;
6
- /**
7
- * Events of one of the view's slots until `end` or the returned stop; `end` is for the shell's
8
- * side ending it (an unbind, or the provider gone).
9
- */
10
- subscribe(slot: string, event: string, send: (payload: unknown) => void, end: () => void): () => void;
11
- /** `ui.shell@1`, which the shell serves to every view with no binding. */
12
- shell: {
13
- /** Open the URL, which the host has checked is https, in a new tab with no opener (`noopener`). */
14
- openExternal(url: string): void | Promise<void>;
15
- /** Start the shell's own sign-in, as its first run does. */
16
- signIn(): void | Promise<void>;
17
- };
18
- /** A line for the view's Actor's log. */
19
- log(level: "info" | "warn" | "error", message: string, fields?: Record<string, unknown>): void;
20
- }
21
- type Size = {
22
- width: number;
23
- height: number;
24
- };
25
- /**
26
- * Hand a frame its port: post the hello with the other end to the frame's window, which has an
27
- * opaque origin, so the target origin is `*`; the frame accepts it only from its parent.
28
- */
29
- export declare function openFrame(frameWindow: {
30
- postMessage(message: unknown, targetOrigin: string, transfer: unknown[]): void;
31
- }): PortLike;
32
- /**
33
- * The shell's end of a view's frame. It drives `ui.view@1` (load, mount, resize, unmount), tells
34
- * the frame which slots are bound, and serves what the frame asks: calls and subscriptions on the
35
- * view's slots through `handlers`, and `ui.shell@1` itself. The frame isn't trusted: every message
36
- * is checked, and one that doesn't fit is dropped or refused.
37
- */
38
- export declare class FrameHost {
39
- #private;
40
- /** The latest height not yet passed on, and the wait before the next may be. */
41
- constructor(port: PortLike, handlers: FrameHandlers);
42
- /** Import the view's bundle in the frame and run its `start`; `slots` says which are bound. */
43
- load(options: {
44
- src: string;
45
- actorId: string;
46
- module: string;
47
- slots: Record<string, boolean>;
48
- }): Promise<void>;
49
- /** A slot became bound or unbound; `bound` again for a bound slot means its provider came back. */
50
- slot(name: string, bound: boolean): void;
51
- mount(theme: Record<string, string>, size: Size): Promise<void>;
52
- resize(size: Size): Promise<void>;
53
- unmount(): Promise<void>;
54
- /** Stop: every subscription ends, and what waits on the frame fails. */
55
- close(): void;
56
- }
57
- export {};