@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,753 +0,0 @@
1
- // src/errors.ts
2
- var BRAND = /* @__PURE__ */ Symbol.for("@agentorg/sdk/error");
3
- var isBranded = (value, name) => typeof value === "object" && value !== null && value[BRAND] === name;
4
- var instanceOf = (asked, base2, name, value) => (
5
- // The name is given, not read from the class: a bundler may rename a class.
6
- asked === base2 ? isBranded(value, name) : Function.prototype[Symbol.hasInstance].call(asked, value)
7
- );
8
- var NotConnected = class _NotConnected extends Error {
9
- static [Symbol.hasInstance](value) {
10
- return instanceOf(this, _NotConnected, "NotConnected", value);
11
- }
12
- name = "NotConnected";
13
- /** The slot or export that isn't connected. */
14
- target;
15
- constructor(target) {
16
- super(`${target} is not connected.`);
17
- this.target = target;
18
- }
19
- };
20
- var Refused = class _Refused extends Error {
21
- static [Symbol.hasInstance](value) {
22
- return instanceOf(this, _Refused, "Refused", value);
23
- }
24
- name = "Refused";
25
- code;
26
- constructor(code, message) {
27
- super(message);
28
- this.code = code;
29
- }
30
- };
31
- var OutcomeUnknown = class _OutcomeUnknown extends Error {
32
- static [Symbol.hasInstance](value) {
33
- return instanceOf(this, _OutcomeUnknown, "OutcomeUnknown", value);
34
- }
35
- name = "OutcomeUnknown";
36
- constructor(message = "The connection dropped before the call's outcome was known.") {
37
- super(message);
38
- }
39
- };
40
- for (const [error, name] of [
41
- [NotConnected, "NotConnected"],
42
- [Refused, "Refused"],
43
- [OutcomeUnknown, "OutcomeUnknown"]
44
- ])
45
- Object.defineProperty(error.prototype, BRAND, { value: name });
46
- function errorBodyOf(error) {
47
- if (error instanceof Refused)
48
- return { name: "Refused", message: error.message, code: error.code };
49
- if (error instanceof NotConnected) return { name: "NotConnected", message: error.message };
50
- if (error instanceof OutcomeUnknown) return { name: "OutcomeUnknown", message: error.message };
51
- return {
52
- name: "Refused",
53
- message: error instanceof Error ? error.message : String(error),
54
- code: "failed"
55
- };
56
- }
57
- function errorFromBody(body, target) {
58
- if (body.name === "NotConnected") return new NotConnected(target);
59
- if (body.name === "OutcomeUnknown") return new OutcomeUnknown(body.message);
60
- return new Refused(body.code ?? "refused", body.message);
61
- }
62
-
63
- // src/frame-protocol.ts
64
- var FRAME_HELLO = "frame/1";
65
- function isShellInterface(iface) {
66
- return iface.kind === "rpc" && iface.name === "ui.shell" && iface.major === 1;
67
- }
68
-
69
- // src/module.ts
70
- function isFrameInterface(iface) {
71
- return iface.kind === "rpc" && iface.name === "ui.view" && iface.major === 1;
72
- }
73
- var MODULE = "agentorg.module/1";
74
- function isModuleDefinition(value) {
75
- return typeof value === "object" && value !== null && value.agentorg === MODULE;
76
- }
77
-
78
- // src/runtime.ts
79
- function check(schema, value, where, code = "invalid") {
80
- const result = schema.safeParse(value);
81
- if (result.success) return result.data;
82
- const issue = result.error.issues[0];
83
- throw new Refused(
84
- code,
85
- `${where}: ${issue ? `${issue.path.map(String).join(".") || "value"} ${issue.message}` : "invalid"}`
86
- );
87
- }
88
- var NAME = /^[a-z][A-Za-z0-9_]*$/;
89
- var own = (record, key) => Object.hasOwn(record, key) ? record[key] : void 0;
90
- function createRuntime(definition, options) {
91
- const slots = /* @__PURE__ */ new Map();
92
- const exported = /* @__PURE__ */ new Map();
93
- const slotHandle = (name, iface) => {
94
- const state = { iface, binds: /* @__PURE__ */ new Set(), unbinds: /* @__PURE__ */ new Set(), listeners: /* @__PURE__ */ new Map() };
95
- slots.set(name, state);
96
- const provider = () => {
97
- if (!state.binding) throw new NotConnected(name);
98
- return state.binding.provider;
99
- };
100
- const base2 = {
101
- get bound() {
102
- return state.binding !== void 0;
103
- },
104
- onBind(fn) {
105
- state.binds.add(fn);
106
- return () => void state.binds.delete(fn);
107
- },
108
- onUnbind(fn) {
109
- state.unbinds.add(fn);
110
- return () => void state.unbinds.delete(fn);
111
- }
112
- };
113
- switch (iface.kind) {
114
- case "rpc":
115
- return Object.assign(base2, {
116
- call: Object.fromEntries(
117
- Object.entries(iface.methods).map(([method, spec]) => [
118
- method,
119
- async (input) => {
120
- const target2 = provider();
121
- const parsed = check(spec.input, input, `${name}.${method} input`);
122
- if (!target2.call)
123
- throw new Refused("unimplemented", `${name} isn't served by an rpc provider.`);
124
- return check(
125
- spec.output,
126
- await target2.call(method, parsed),
127
- `${name}.${method} output`,
128
- "bad_output"
129
- );
130
- }
131
- ])
132
- ),
133
- on(event, fn) {
134
- if (!own(iface.events, event)) throw new TypeError(`${name} has no event ${event}.`);
135
- const set = state.listeners.get(event) ?? /* @__PURE__ */ new Set();
136
- state.listeners.set(event, set);
137
- set.add(fn);
138
- options.onListen?.(name, event);
139
- return () => void set.delete(fn);
140
- }
141
- });
142
- case "stream":
143
- return Object.assign(base2, {
144
- async open(params) {
145
- const target2 = provider();
146
- const parsed = check(iface.open, params, `${name} open`);
147
- if (!target2.open)
148
- throw new Refused("unimplemented", `${name} isn't served by a stream provider.`);
149
- return target2.open(parsed);
150
- }
151
- });
152
- case "http":
153
- return Object.assign(base2, {
154
- async fetch(request) {
155
- const target2 = provider();
156
- if (!target2.fetch)
157
- throw new Refused("unimplemented", `${name} isn't served by an http provider.`);
158
- return target2.fetch(request);
159
- }
160
- });
161
- }
162
- };
163
- const exportHandle = (name, iface) => {
164
- const state = { iface, withdrawn: false };
165
- exported.set(name, state);
166
- const live = () => {
167
- if (state.withdrawn) throw new NotConnected(name);
168
- };
169
- const withdraw = () => {
170
- if (state.withdrawn) return;
171
- state.withdrawn = true;
172
- options.onWithdraw?.(name);
173
- };
174
- const store = (impl) => {
175
- live();
176
- state.impl = impl;
177
- };
178
- if (isFrameInterface(iface)) return { implement: store, withdraw };
179
- switch (iface.kind) {
180
- case "rpc":
181
- return {
182
- implement: store,
183
- emit(event, payload, emitting) {
184
- live();
185
- const spec = own(iface.events, event);
186
- if (!spec) throw new TypeError(`${name} has no event ${event}.`);
187
- options.onEmit(
188
- name,
189
- event,
190
- check(spec.payload, payload, `${name}.${event} payload`),
191
- emitting?.to
192
- );
193
- },
194
- withdraw
195
- };
196
- case "stream":
197
- return { accept: store, withdraw };
198
- case "http":
199
- return { serve: store, withdraw };
200
- }
201
- };
202
- const target = (name, kind) => {
203
- const state = exported.get(name);
204
- if (!state || state.withdrawn) throw new NotConnected(name);
205
- const frame2 = isFrameInterface(state.iface);
206
- if (frame2 !== (kind === "frame") || !frame2 && state.iface.kind !== kind)
207
- throw new TypeError(
208
- `${name} isn't ${kind === "frame" ? "a ui.view@1" : `an ${kind}`} export.`
209
- );
210
- return state;
211
- };
212
- const implemented = (state, name) => {
213
- if (state.impl === void 0)
214
- throw new Refused("unimplemented", `${name} hasn't been implemented yet.`);
215
- return state.impl;
216
- };
217
- const exposed = /* @__PURE__ */ new Map();
218
- const exposedWatchers = /* @__PURE__ */ new Set();
219
- const exposedChanged = () => {
220
- const failed = (error) => options.log.error("An onExposed handler threw.", { error: String(error) });
221
- for (const fn of [...exposedWatchers])
222
- try {
223
- const done = fn();
224
- if (done instanceof Promise) done.catch(failed);
225
- } catch (error) {
226
- failed(error);
227
- }
228
- };
229
- const listenExposed = (slot, state, event) => {
230
- const entry = state.events.get(event);
231
- if (state.gone || !entry || entry.stop || !entry.fns.size) return;
232
- let ended = false;
233
- let stop;
234
- stop = state.source.subscribe(
235
- event,
236
- (payload) => {
237
- for (const fn of [...entry.fns])
238
- try {
239
- fn(payload);
240
- } catch (error) {
241
- options.log.error("An event handler threw.", { slot, event, error: String(error) });
242
- }
243
- },
244
- // Ended by the provider going: the interest stays for when it is usable again.
245
- () => {
246
- ended = true;
247
- if (entry.stop === stop) entry.stop = void 0;
248
- }
249
- );
250
- if (!ended) entry.stop = stop;
251
- };
252
- const exposedHandle = (slot, state) => {
253
- const { described, provider } = state.source;
254
- return Object.freeze({
255
- slot,
256
- described,
257
- provider: Object.freeze({ actor: provider.actor, export: provider.export }),
258
- call: Object.freeze(
259
- Object.fromEntries(
260
- (described.kind === "rpc" ? Object.keys(described.methods) : []).map((method) => [
261
- method,
262
- async (input) => {
263
- if (state.gone) throw new NotConnected(slot);
264
- return state.source.call(method, input);
265
- }
266
- ])
267
- )
268
- ),
269
- on(event, fn) {
270
- if (described.kind !== "rpc" || !own(described.events, event))
271
- throw new TypeError(`${slot} has no event ${event}.`);
272
- const entry = state.events.get(event) ?? { fns: /* @__PURE__ */ new Set() };
273
- state.events.set(event, entry);
274
- entry.fns.add(fn);
275
- listenExposed(slot, state, event);
276
- return () => {
277
- entry.fns.delete(fn);
278
- if (entry.fns.size) return;
279
- entry.stop?.();
280
- entry.stop = void 0;
281
- };
282
- }
283
- });
284
- };
285
- const unexpose = (slot) => {
286
- const state = exposed.get(slot);
287
- if (!state) return;
288
- exposed.delete(slot);
289
- state.gone = true;
290
- for (const entry of state.events.values()) {
291
- entry.stop?.();
292
- entry.stop = void 0;
293
- }
294
- exposedChanged();
295
- };
296
- const expose = (slot, source) => {
297
- const here = exposed.get(slot);
298
- if (here && here.source.described.hash === source.described.hash && here.source.provider.actor === source.provider.actor && here.source.provider.export === source.provider.export) {
299
- here.source = source;
300
- for (const [event, entry] of here.events) {
301
- entry.stop?.();
302
- entry.stop = void 0;
303
- listenExposed(slot, here, event);
304
- }
305
- return;
306
- }
307
- if (here) unexpose(slot);
308
- const state = { source, gone: false, events: /* @__PURE__ */ new Map() };
309
- state.handle = exposedHandle(slot, state);
310
- exposed.set(slot, state);
311
- exposedChanged();
312
- };
313
- const ctx = {
314
- slots: Object.fromEntries(
315
- Object.entries(definition.slots).map(([name, iface]) => [name, slotHandle(name, iface)])
316
- ),
317
- exports: Object.assign(
318
- Object.fromEntries(
319
- Object.entries(definition.exports).map(([name, iface]) => [
320
- name,
321
- exportHandle(name, iface)
322
- ])
323
- ),
324
- {
325
- add(name, iface) {
326
- if (!NAME.test(name) || name === "add")
327
- throw new TypeError(`${JSON.stringify(name)} isn't a valid export name.`);
328
- const existing = exported.get(name);
329
- if (existing && !existing.withdrawn)
330
- throw new TypeError(`An export named ${name} is already offered.`);
331
- const handle = exportHandle(name, iface);
332
- options.onAdd?.(name, iface, handle);
333
- return handle;
334
- }
335
- }
336
- ),
337
- self: options.self,
338
- log: options.log,
339
- exposed: () => Object.freeze([...exposed.values()].map((state) => state.handle)),
340
- onExposed(fn) {
341
- exposedWatchers.add(fn);
342
- return () => void exposedWatchers.delete(fn);
343
- }
344
- };
345
- const serving = (exportName) => {
346
- const state = target(exportName, "http");
347
- const handler = implemented(
348
- state,
349
- exportName
350
- );
351
- return async (request) => handler(request);
352
- };
353
- const accepting = (exportName, params) => {
354
- const state = target(exportName, "stream");
355
- const parsed = check(state.iface.open, params, `${exportName} open`);
356
- const handler = implemented(
357
- state,
358
- exportName
359
- );
360
- return async (stream) => {
361
- await handler(parsed, stream);
362
- };
363
- };
364
- const notify = (slot, handlers) => {
365
- const failed = (error) => options.log.error("A slot handler threw.", { slot, error: String(error) });
366
- for (const fn of [...handlers])
367
- try {
368
- const done = fn();
369
- if (done instanceof Promise) done.catch(failed);
370
- } catch (error) {
371
- failed(error);
372
- }
373
- };
374
- const unbind = (slot) => {
375
- const state = slots.get(slot);
376
- if (!state) throw new TypeError(`No slot ${slot}.`);
377
- if (!state.binding) return;
378
- state.binding = void 0;
379
- notify(slot, state.unbinds);
380
- };
381
- return {
382
- ctx,
383
- async start() {
384
- await definition.start(ctx);
385
- },
386
- bind(slot, provider) {
387
- const state = slots.get(slot);
388
- if (!state) throw new TypeError(`No slot ${slot}.`);
389
- unbind(slot);
390
- const binding = { provider };
391
- state.binding = binding;
392
- notify(slot, state.binds);
393
- return {
394
- emit(event, payload) {
395
- const iface = state.iface;
396
- const spec = iface.kind === "rpc" ? own(iface.events, event) : void 0;
397
- if (!spec) throw new TypeError(`${slot} has no event ${event}.`);
398
- const value = check(spec.payload, payload, `${slot}.${event}`, "bad_output");
399
- if (state.binding !== binding) return;
400
- for (const fn of [...state.listeners.get(event) ?? []]) fn(value);
401
- }
402
- };
403
- },
404
- unbind,
405
- usable(slot) {
406
- const state = slots.get(slot);
407
- if (!state) throw new TypeError(`No slot ${slot}.`);
408
- if (state.binding) notify(slot, state.binds);
409
- },
410
- expose,
411
- unexpose,
412
- async call(exportName, method, input, caller) {
413
- const state = target(exportName, "rpc");
414
- const spec = own(state.iface.methods, method);
415
- if (!spec) throw new TypeError(`${exportName} has no method ${method}.`);
416
- const parsed = check(spec.input, input, `${exportName}.${method} input`);
417
- const handler = own(
418
- implemented(state, exportName),
419
- method
420
- );
421
- if (!handler)
422
- throw new Refused("unimplemented", `${exportName}.${method} isn't implemented.`);
423
- return check(
424
- spec.output,
425
- await handler(parsed, { caller }),
426
- `${exportName}.${method} output`,
427
- "bad_output"
428
- );
429
- },
430
- accepting,
431
- async open(exportName, params, stream) {
432
- await accepting(exportName, params)(stream);
433
- },
434
- serving,
435
- async fetch(exportName, request) {
436
- return serving(exportName)(request);
437
- },
438
- mount(exportName, el, options2) {
439
- const state = target(exportName, "frame");
440
- const methods = state.iface.methods;
441
- const parsed = check(methods.mount?.input, options2, `${exportName} mount`);
442
- const view = implemented(state, exportName);
443
- const cleanup = view.mount(el, parsed);
444
- return {
445
- resize(size) {
446
- const { size: checked } = check(
447
- methods.resize?.input,
448
- { size },
449
- `${exportName} resize`
450
- );
451
- view.resize?.(checked);
452
- },
453
- unmount() {
454
- cleanup?.();
455
- }
456
- };
457
- },
458
- withdrawn(exportName) {
459
- return exported.get(exportName)?.withdrawn ?? false;
460
- }
461
- };
462
- }
463
-
464
- // src/frame.ts
465
- function runFrame(options) {
466
- const { port } = options;
467
- const send = (message) => port.postMessage(message);
468
- let nextId = 0;
469
- const pending = /* @__PURE__ */ new Map();
470
- const request = (message, target) => new Promise((resolve, reject) => {
471
- const id = ++nextId;
472
- pending.set(id, { resolve, reject, target });
473
- send({ ...message, id });
474
- });
475
- let runtime;
476
- let definition;
477
- let loading = false;
478
- let mounted;
479
- const bindings = /* @__PURE__ */ new Map();
480
- let early = /* @__PURE__ */ new Map();
481
- const listened = /* @__PURE__ */ new Map();
482
- const subscriptions = /* @__PURE__ */ new Map();
483
- const log = {
484
- info: (message, fields) => send({ op: "log", level: "info", message, ...fields ? { fields } : {} }),
485
- warn: (message, fields) => send({ op: "log", level: "warn", message, ...fields ? { fields } : {} }),
486
- error: (message, fields) => send({ op: "log", level: "error", message, ...fields ? { fields } : {} })
487
- };
488
- const subscribe = (slot, event) => {
489
- const events = listened.get(slot) ?? /* @__PURE__ */ new Map();
490
- listened.set(slot, events);
491
- if (!events.has(event)) events.set(event, void 0);
492
- if (!bindings.has(slot) || events.get(event) !== void 0) return;
493
- const sub = ++nextId;
494
- subscriptions.set(sub, { slot, event });
495
- events.set(event, sub);
496
- send({ op: "subscribe", sub, slot, event });
497
- };
498
- const stopAll = (slot, tell) => {
499
- const events = listened.get(slot);
500
- for (const [event, sub] of events ?? []) {
501
- if (sub === void 0) continue;
502
- subscriptions.delete(sub);
503
- events?.set(event, void 0);
504
- if (tell) send({ op: "unsubscribe", sub });
505
- }
506
- };
507
- const resubscribe = (slot) => {
508
- stopAll(slot, true);
509
- for (const event of listened.get(slot)?.keys() ?? []) subscribe(slot, event);
510
- };
511
- const bind = (slot) => {
512
- if (!runtime) return;
513
- bindings.set(
514
- slot,
515
- runtime.bind(slot, {
516
- call: (method, input) => request({ op: "call", slot, method, input }, slot),
517
- open: async () => {
518
- throw new Refused("unimplemented", `${slot}: a view's stream slots aren't served yet.`);
519
- },
520
- fetch: async () => {
521
- throw new Refused("unimplemented", `${slot}: a view's http slots aren't served yet.`);
522
- }
523
- })
524
- );
525
- resubscribe(slot);
526
- };
527
- const onSlot = (slot, bound) => {
528
- if (early) return void early.set(slot, bound);
529
- const iface = definition && Object.hasOwn(definition.slots, slot) ? definition.slots[slot] : void 0;
530
- if (!runtime || !iface || isShellInterface(iface)) return;
531
- if (!bound) {
532
- bindings.delete(slot);
533
- stopAll(slot, true);
534
- return runtime.unbind(slot);
535
- }
536
- if (bindings.has(slot)) {
537
- resubscribe(slot);
538
- return runtime.usable(slot);
539
- }
540
- bind(slot);
541
- };
542
- const viewExport = () => {
543
- for (const [name, iface] of Object.entries(definition?.exports ?? {}))
544
- if (isFrameInterface(iface)) return name;
545
- throw new Refused("unimplemented", "This module exports no ui.view@1.");
546
- };
547
- const answer = async (id, run) => {
548
- try {
549
- send({ op: "reply", id, result: await run() ?? {} });
550
- } catch (error) {
551
- send({ op: "reply", id, error: errorBodyOf(error) });
552
- }
553
- };
554
- const handle = (message) => {
555
- switch (message.op) {
556
- case "load":
557
- return answer(message.id, async () => {
558
- if (runtime || loading)
559
- throw new Refused("state", "This frame has loaded a view already.");
560
- loading = true;
561
- for (const [slot, isBound] of Object.entries(message.slots)) early?.set(slot, isBound);
562
- try {
563
- const loaded = await options.load(message.src);
564
- const found = loaded?.default;
565
- if (!isModuleDefinition(found) || found.placement !== "view")
566
- throw new Refused("invalid", `${message.src} isn't a view module.`);
567
- definition = found;
568
- const created = createRuntime(found, {
569
- self: message.self,
570
- log,
571
- // A view serves only ui.view@1, which the shell drives directly; nothing reaches its
572
- // other exports, so their events go nowhere.
573
- onEmit: () => {
574
- },
575
- onListen: subscribe
576
- });
577
- await created.start();
578
- runtime = created;
579
- for (const [slot, iface] of Object.entries(found.slots))
580
- if (isShellInterface(iface))
581
- bindings.set(
582
- slot,
583
- created.bind(slot, {
584
- call: (method, input) => request({ op: "shell", method, input }, slot)
585
- })
586
- );
587
- const bound = early;
588
- early = void 0;
589
- for (const [slot, isBound] of bound ?? []) if (isBound) onSlot(slot, true);
590
- } catch (error) {
591
- definition = void 0;
592
- early = /* @__PURE__ */ new Map();
593
- throw error;
594
- } finally {
595
- loading = false;
596
- }
597
- });
598
- case "slot":
599
- return onSlot(message.name, message.bound);
600
- case "mount":
601
- return answer(message.id, () => {
602
- if (!runtime) throw new Refused("state", "Nothing is loaded to mount.");
603
- if (mounted) throw new Refused("state", "The view is mounted already.");
604
- options.theme?.(message.theme);
605
- mounted = runtime.mount(viewExport(), options.root, {
606
- theme: message.theme,
607
- size: message.size
608
- });
609
- });
610
- case "resize":
611
- return answer(message.id, () => {
612
- if (!mounted) throw new Refused("state", "The view isn't mounted.");
613
- mounted.resize(message.size);
614
- });
615
- case "unmount":
616
- return answer(message.id, () => {
617
- const view = mounted;
618
- mounted = void 0;
619
- view?.unmount();
620
- });
621
- case "event": {
622
- const subscription = subscriptions.get(message.sub);
623
- if (!subscription) return;
624
- try {
625
- bindings.get(subscription.slot)?.emit(subscription.event, message.payload);
626
- } catch (error) {
627
- log.warn("An event didn't fit its schema.", { ...subscription, error: String(error) });
628
- }
629
- return;
630
- }
631
- case "end": {
632
- const subscription = subscriptions.get(message.sub);
633
- if (!subscription) return;
634
- subscriptions.delete(message.sub);
635
- const events = listened.get(subscription.slot);
636
- if (events?.get(subscription.event) === message.sub)
637
- events.set(subscription.event, void 0);
638
- return;
639
- }
640
- case "reply": {
641
- const waiting = pending.get(message.id);
642
- if (!waiting) return;
643
- pending.delete(message.id);
644
- if ("error" in message)
645
- waiting.reject(errorFromBody(message.error, waiting.target));
646
- else waiting.resolve(message.result);
647
- return;
648
- }
649
- }
650
- };
651
- port.onmessage = (event) => {
652
- try {
653
- void handle(event.data);
654
- } catch (error) {
655
- log.error("The frame couldn't handle a message from the shell.", { error: String(error) });
656
- }
657
- };
658
- return {
659
- failed(error) {
660
- log.error(error instanceof Error ? error.message : String(error), {
661
- ...error instanceof Error && error.stack ? { stack: error.stack } : {}
662
- });
663
- },
664
- close() {
665
- port.onmessage = null;
666
- for (const [, waiting] of pending) waiting.reject(new OutcomeUnknown("The frame closed."));
667
- pending.clear();
668
- port.close();
669
- }
670
- };
671
- }
672
-
673
- // src/frame-base.ts
674
- var FRAME_BASE = `
675
- :where(*, *::before, *::after) { box-sizing: border-box; }
676
- :where(html, body) { height: 100%; margin: 0; background: transparent; }
677
- :where(body) {
678
- overflow: auto; scrollbar-width: none;
679
- color: var(--fg); font: 14px/1.45 var(--font, ui-sans-serif, system-ui, sans-serif);
680
- -webkit-font-smoothing: antialiased;
681
- }
682
- :where(body)::-webkit-scrollbar { display: none; }
683
- :where(body > :only-child) { min-height: 100%; }
684
- :where(h1, h2, h3, h4) { margin: 0 0 8px; font-weight: 600; letter-spacing: -0.01em; }
685
- :where(h1) { font-size: 20px; }
686
- :where(h2) { font-size: 16px; }
687
- :where(h3, h4) { font-size: 14px; }
688
- :where(p) { margin: 0 0 8px; }
689
- :where(small) { color: var(--muted); font-size: 12.5px; }
690
- :where(a) { color: inherit; text-underline-offset: 2px; }
691
- :where(hr) { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
692
- :where(ul, ol) { margin: 0 0 10px; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
693
- :where(li) { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--raised); }
694
- :where(button) {
695
- height: 34px; padding: 0 12px; border: 0; border-radius: 9px; cursor: pointer;
696
- background: var(--hover); color: var(--fg); font: inherit; font-weight: 500;
697
- }
698
- :where(button:hover) { background: var(--selected); }
699
- :where(button:disabled) { opacity: 0.5; cursor: default; }
700
- :where(button[type="submit"], button.primary) { background: var(--accent); color: var(--accent-fg); font-weight: 600; }
701
- :where(input:not([type]), input[type="text"], input[type="search"], input[type="number"], input[type="url"], input[type="email"], select) {
702
- height: 34px; padding: 0 10px; border: 0; border-radius: 9px; outline: 0;
703
- background: var(--raised); color: var(--fg); font: inherit;
704
- }
705
- :where(textarea) { padding: 8px 10px; border: 0; border-radius: 9px; outline: 0; resize: none; background: var(--raised); color: var(--fg); font: inherit; }
706
- :where(input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible) { box-shadow: 0 0 0 1.5px var(--ring); outline: 0; }
707
- :where(input[type="checkbox"]) {
708
- appearance: none; width: 16px; height: 16px; margin: 0; flex: none; display: grid; place-items: center;
709
- border: 1.5px solid var(--faint); border-radius: 5px; cursor: pointer;
710
- }
711
- :where(input[type="checkbox"]:checked) { background: var(--ok); border-color: var(--ok); }
712
- :where(input[type="checkbox"]:checked)::after {
713
- content: ""; width: 4px; height: 8px; border: solid white; border-width: 0 2px 2px 0;
714
- transform: translateY(-1px) rotate(45deg);
715
- }
716
- :where(li:has(> input[type="checkbox"]:checked) > span) { color: var(--faint); text-decoration: line-through; }
717
- :where(form) { display: flex; gap: 6px; }
718
- :where(form > input, form > textarea) { flex: 1; min-width: 0; }
719
- :where(table) { width: 100%; border-collapse: collapse; font-size: 13px; }
720
- :where(th) { padding: 0 8px 6px; text-align: left; color: var(--faint); font-weight: 500; font-size: 12px; }
721
- :where(td) { padding: 7px 8px; border-top: 1px solid var(--line); }
722
- :where(code, pre) { font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
723
- :where(code) { padding: 1px 5px; border-radius: 5px; background: var(--raised); }
724
- :where(pre) { margin: 0 0 10px; padding: 10px 12px; border-radius: 10px; background: var(--raised); overflow: auto; }
725
- :where(pre code) { padding: 0; background: none; }
726
- :where(progress) { appearance: none; width: 100%; height: 4px; border: 0; border-radius: 2px; background: var(--raised); }
727
- :where(progress)::-webkit-progress-bar { background: var(--raised); border-radius: 2px; }
728
- :where(progress)::-webkit-progress-value { background: var(--ok); border-radius: 2px; }
729
- :where(progress)::-moz-progress-bar { background: var(--ok); border-radius: 2px; }
730
- `;
731
-
732
- // src/frame-entry.ts
733
- var self = globalThis;
734
- var frame;
735
- var base = self.document.createElement("style");
736
- base.textContent = FRAME_BASE;
737
- self.document.head.prepend(base);
738
- self.addEventListener("message", (event) => {
739
- const port = event.ports[0];
740
- if (frame || event.source !== self.parent || event.data !== FRAME_HELLO || !port) return;
741
- frame = runFrame({
742
- port,
743
- root: self.document.body,
744
- // A computed specifier: the bundler leaves it to the browser.
745
- load: (src) => import(src),
746
- theme(tokens) {
747
- for (const [name, value] of Object.entries(tokens))
748
- if (name.startsWith("--")) self.document.documentElement.style.setProperty(name, value);
749
- }
750
- });
751
- });
752
- self.addEventListener("error", (event) => frame?.failed(event.error ?? event.message));
753
- self.addEventListener("unhandledrejection", (event) => frame?.failed(event.reason));