@almadar/shell-runtime 0.0.0-stage → 0.1.0

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 (180) hide show
  1. package/dist/chunk-2JU7Y4KU.js +21 -0
  2. package/dist/chunk-46RWK2B5.js +28 -0
  3. package/dist/chunk-4J2QEIUV.js +78 -0
  4. package/dist/chunk-4SEK5ER2.js +8 -0
  5. package/dist/chunk-4ZICQ5PM.js +192 -0
  6. package/dist/chunk-53IPZXDP.js +76 -0
  7. package/dist/chunk-5D63EMO5.js +16 -0
  8. package/dist/chunk-64IH2SMY.js +22 -0
  9. package/dist/chunk-7SDV3QWR.js +67 -0
  10. package/dist/chunk-CPSQXEJ6.js +55 -0
  11. package/dist/chunk-CQP5XAX6.js +173 -0
  12. package/dist/chunk-CROS2GEX.js +49 -0
  13. package/dist/chunk-D4XJTBLB.js +217 -0
  14. package/dist/chunk-D5USD2EX.js +232 -0
  15. package/dist/chunk-DYOJGLIX.js +25 -0
  16. package/dist/chunk-ELBLT2HZ.js +1 -0
  17. package/dist/chunk-EV56K4GB.js +63 -0
  18. package/dist/chunk-EZZYLTWY.js +1 -0
  19. package/dist/chunk-FQ6IZMIU.js +10 -0
  20. package/dist/chunk-FWA5K7Q2.js +48 -0
  21. package/dist/chunk-HC6ERSAH.js +55 -0
  22. package/dist/chunk-HLOUDLPI.js +48 -0
  23. package/dist/chunk-HMK6YMQS.js +135 -0
  24. package/dist/chunk-HNOAZWFH.js +19 -0
  25. package/dist/chunk-IHQLE5M7.js +62 -0
  26. package/dist/chunk-IOPUS6Q5.js +15 -0
  27. package/dist/chunk-JFWFDUTR.js +35 -0
  28. package/dist/chunk-LZIOTBFX.js +1 -0
  29. package/dist/chunk-MHYSHSRG.js +54 -0
  30. package/dist/chunk-MLKGABMK.js +7 -0
  31. package/dist/chunk-MZKIL5IN.js +74 -0
  32. package/dist/chunk-NAECVIAR.js +322 -0
  33. package/dist/chunk-NATGCIVM.js +583 -0
  34. package/dist/chunk-O57GKTYU.js +30 -0
  35. package/dist/chunk-ODJCZ27I.js +50 -0
  36. package/dist/chunk-P53CKOME.js +1 -0
  37. package/dist/chunk-Q2H75UYT.js +92 -0
  38. package/dist/chunk-Q7JK4KY7.js +9 -0
  39. package/dist/chunk-QELZ6TEJ.js +208 -0
  40. package/dist/chunk-QQRDUMB2.js +40 -0
  41. package/dist/chunk-RBUMDYFS.js +681 -0
  42. package/dist/chunk-REPX5QPI.js +57 -0
  43. package/dist/chunk-SAS5KKCR.js +43 -0
  44. package/dist/chunk-SKLMWHQD.js +109 -0
  45. package/dist/chunk-SOQDEPME.js +131 -0
  46. package/dist/chunk-SWPDU752.js +28 -0
  47. package/dist/chunk-T775TUCD.js +18 -0
  48. package/dist/chunk-UBN5JJKZ.js +26 -0
  49. package/dist/chunk-UJHOUZAL.js +36 -0
  50. package/dist/chunk-UP6GGGAN.js +34 -0
  51. package/dist/chunk-VMOBW7RK.js +21 -0
  52. package/dist/chunk-VNMG7NKY.js +69 -0
  53. package/dist/chunk-WNPNNYXY.js +22 -0
  54. package/dist/chunk-XB5GYODW.js +28 -0
  55. package/dist/chunk-XXWNMJI6.js +15 -0
  56. package/dist/chunk-YL2SO5TP.js +334 -0
  57. package/dist/chunk-YO4LWS3I.js +606 -0
  58. package/dist/chunk-ZAQSS47X.js +157 -0
  59. package/dist/chunk-ZCQUUJIF.js +129 -0
  60. package/dist/client/EventTransport.d.ts +131 -0
  61. package/dist/client/EventTransport.js +2 -0
  62. package/dist/client/ServerBridge.d.ts +126 -0
  63. package/dist/client/ServerBridge.js +3 -0
  64. package/dist/client/awaiting.d.ts +28 -0
  65. package/dist/client/awaiting.js +2 -0
  66. package/dist/client/channel-transport.d.ts +69 -0
  67. package/dist/client/channel-transport.js +2 -0
  68. package/dist/client/circuit-store.d.ts +76 -0
  69. package/dist/client/circuit-store.js +4 -0
  70. package/dist/client/client-kernel.d.ts +113 -0
  71. package/dist/client/client-kernel.js +1 -0
  72. package/dist/client/declared-input-dispatch.d.ts +5 -0
  73. package/dist/client/declared-input-dispatch.js +2 -0
  74. package/dist/client/inbound-dispatch.d.ts +5 -0
  75. package/dist/client/inbound-dispatch.js +2 -0
  76. package/dist/client/local-fold.d.ts +26 -0
  77. package/dist/client/local-fold.js +2 -0
  78. package/dist/client/render-sigils.d.ts +24 -0
  79. package/dist/client/render-sigils.js +2 -0
  80. package/dist/client/state-book.d.ts +37 -0
  81. package/dist/client/state-book.js +2 -0
  82. package/dist/client/trait-mount-error.d.ts +9 -0
  83. package/dist/client/trait-mount-error.js +2 -0
  84. package/dist/client/trait-types.d.ts +67 -0
  85. package/dist/client/trait-types.js +1 -0
  86. package/dist/credentials/env-vars.d.ts +14 -0
  87. package/dist/credentials/env-vars.js +3 -0
  88. package/dist/credentials/scope.d.ts +50 -0
  89. package/dist/credentials/scope.js +2 -0
  90. package/dist/credentials/seed.d.ts +21 -0
  91. package/dist/credentials/seed.js +2 -0
  92. package/dist/credentials/store.d.ts +110 -0
  93. package/dist/credentials/store.js +2 -0
  94. package/dist/effects/in-flight-calls.d.ts +36 -0
  95. package/dist/effects/in-flight-calls.js +2 -0
  96. package/dist/effects/on-device-model.d.ts +22 -0
  97. package/dist/effects/on-device-model.js +2 -0
  98. package/dist/events/EventBus.d.ts +90 -0
  99. package/dist/events/EventBus.js +2 -0
  100. package/dist/events/emit-stamp.d.ts +47 -0
  101. package/dist/events/emit-stamp.js +2 -0
  102. package/dist/index-hT1xCdTq.d.ts +46 -0
  103. package/dist/index.d.ts +60 -0
  104. package/dist/index.js +59 -0
  105. package/dist/kernel/beacon.d.ts +32 -0
  106. package/dist/kernel/beacon.js +2 -0
  107. package/dist/kernel/decode.d.ts +15 -0
  108. package/dist/kernel/decode.js +2 -0
  109. package/dist/kernel/engine.d.ts +94 -0
  110. package/dist/kernel/engine.js +11 -0
  111. package/dist/kernel/frame-applier.d.ts +43 -0
  112. package/dist/kernel/frame-applier.js +2 -0
  113. package/dist/kernel/host.d.ts +95 -0
  114. package/dist/kernel/host.js +9 -0
  115. package/dist/kernel/http.d.ts +302 -0
  116. package/dist/kernel/http.js +6 -0
  117. package/dist/kernel/lane.d.ts +28 -0
  118. package/dist/kernel/lane.js +2 -0
  119. package/dist/kernel/oauth-effects.d.ts +25 -0
  120. package/dist/kernel/oauth-effects.js +7 -0
  121. package/dist/kernel/oauth-port.d.ts +31 -0
  122. package/dist/kernel/oauth-port.js +2 -0
  123. package/dist/kernel/os-port.d.ts +133 -0
  124. package/dist/kernel/os-port.js +2 -0
  125. package/dist/kernel/program-effects.d.ts +65 -0
  126. package/dist/kernel/program-effects.js +2 -0
  127. package/dist/kernel/wire.d.ts +66 -0
  128. package/dist/kernel/wire.js +1 -0
  129. package/dist/loader/http-loader.d.ts +111 -0
  130. package/dist/loader/http-loader.js +2 -0
  131. package/dist/loader/lazy-page.d.ts +12 -0
  132. package/dist/loader/lazy-page.js +2 -0
  133. package/dist/loader/schema-loader.d.ts +160 -0
  134. package/dist/loader/schema-loader.js +1 -0
  135. package/dist/persistence/native-memory.d.ts +28 -0
  136. package/dist/persistence/native-memory.js +2 -0
  137. package/dist/runtime/effects/composition/compose-behaviors.d.ts +58 -0
  138. package/dist/runtime/effects/composition/compose-behaviors.js +4 -0
  139. package/dist/runtime/effects/composition/event-wiring.d.ts +38 -0
  140. package/dist/runtime/effects/composition/event-wiring.js +2 -0
  141. package/dist/runtime/effects/composition/index.d.ts +5 -0
  142. package/dist/runtime/effects/composition/index.js +6 -0
  143. package/dist/runtime/effects/composition/layout-strategy.d.ts +35 -0
  144. package/dist/runtime/effects/composition/layout-strategy.js +2 -0
  145. package/dist/runtime/effects/composition/pipe.d.ts +25 -0
  146. package/dist/runtime/effects/composition/pipe.js +2 -0
  147. package/dist/runtime/entities/mockStoreSeed.d.ts +56 -0
  148. package/dist/runtime/entities/mockStoreSeed.js +3 -0
  149. package/dist/runtime/entities/seedBrowserStore.d.ts +28 -0
  150. package/dist/runtime/entities/seedBrowserStore.js +2 -0
  151. package/dist/runtime/entities/std-mock-seed.d.ts +87 -0
  152. package/dist/runtime/entities/std-mock-seed.js +2 -0
  153. package/dist/runtime/evaluation/local-store-transport.d.ts +68 -0
  154. package/dist/runtime/evaluation/local-store-transport.js +18 -0
  155. package/dist/runtime/evaluation/residence-transport.d.ts +15 -0
  156. package/dist/runtime/evaluation/residence-transport.js +2 -0
  157. package/dist/runtime/evaluation/routed-persistence.d.ts +9 -0
  158. package/dist/runtime/evaluation/routed-persistence.js +2 -0
  159. package/dist/runtime/events/identity/routing.d.ts +84 -0
  160. package/dist/runtime/events/identity/routing.js +2 -0
  161. package/dist/runtime/time/TickScheduler.d.ts +77 -0
  162. package/dist/runtime/time/TickScheduler.js +3 -0
  163. package/dist/runtime/time/cron.d.ts +25 -0
  164. package/dist/runtime/time/cron.js +2 -0
  165. package/dist/runtime/time/duration.d.ts +20 -0
  166. package/dist/runtime/time/duration.js +2 -0
  167. package/dist/runtime/traits/OrbitalTraitParsing.d.ts +34 -0
  168. package/dist/runtime/traits/OrbitalTraitParsing.js +2 -0
  169. package/dist/runtime/traits/listen-targets.d.ts +16 -0
  170. package/dist/runtime/traits/listen-targets.js +3 -0
  171. package/dist/runtime/traits/trait-index.d.ts +35 -0
  172. package/dist/runtime/traits/trait-index.js +3 -0
  173. package/dist/runtime/types.d.ts +574 -0
  174. package/dist/runtime/types.js +2 -0
  175. package/dist/service/default-call-service.d.ts +23 -0
  176. package/dist/service/default-call-service.js +3 -0
  177. package/dist/service/service-provider.d.ts +37 -0
  178. package/dist/service/service-provider.js +2 -0
  179. package/package.json +46 -3
  180. package/README.md +0 -3
@@ -0,0 +1,334 @@
1
+ import { OrbitalSchemaSchema } from '@almadar/core';
2
+
3
+ // src/loader/http-loader.ts
4
+ function isAbsoluteUrl(base) {
5
+ return /^[a-z][a-z0-9+.-]*:/i.test(base);
6
+ }
7
+ var HttpImportChain = class _HttpImportChain {
8
+ chain = [];
9
+ /**
10
+ * Try to add a path to the chain.
11
+ * @returns Error message if circular, null if OK
12
+ */
13
+ push(absolutePath) {
14
+ if (this.chain.includes(absolutePath)) {
15
+ const cycle = [
16
+ ...this.chain.slice(this.chain.indexOf(absolutePath)),
17
+ absolutePath
18
+ ];
19
+ return `Circular import detected: ${cycle.join(" -> ")}`;
20
+ }
21
+ this.chain.push(absolutePath);
22
+ return null;
23
+ }
24
+ /**
25
+ * Remove the last path from the chain.
26
+ */
27
+ pop() {
28
+ this.chain.pop();
29
+ }
30
+ /**
31
+ * Clone the chain for nested loading.
32
+ */
33
+ clone() {
34
+ const newChain = new _HttpImportChain();
35
+ newChain.chain = [...this.chain];
36
+ return newChain;
37
+ }
38
+ };
39
+ var HttpLoaderCache = class {
40
+ cache = /* @__PURE__ */ new Map();
41
+ get(url) {
42
+ return this.cache.get(url);
43
+ }
44
+ set(url, schema) {
45
+ this.cache.set(url, schema);
46
+ }
47
+ has(url) {
48
+ return this.cache.has(url);
49
+ }
50
+ clear() {
51
+ this.cache.clear();
52
+ }
53
+ get size() {
54
+ return this.cache.size;
55
+ }
56
+ };
57
+ var HttpLoader = class {
58
+ options;
59
+ cache;
60
+ constructor(options) {
61
+ this.options = {
62
+ basePath: options.basePath,
63
+ stdLibPath: options.stdLibPath ?? "",
64
+ scopedPaths: options.scopedPaths ?? {},
65
+ fetchOptions: options.fetchOptions,
66
+ timeout: options.timeout ?? 3e4,
67
+ credentials: options.credentials ?? "same-origin"
68
+ };
69
+ this.cache = new HttpLoaderCache();
70
+ }
71
+ /**
72
+ * Load a schema from an import path.
73
+ */
74
+ async load(importPath, fromPath, chain) {
75
+ const importChain = chain ?? new HttpImportChain();
76
+ const resolveResult = this.resolvePath(importPath, fromPath);
77
+ if (!resolveResult.success) {
78
+ return resolveResult;
79
+ }
80
+ const absoluteUrl = resolveResult.data;
81
+ const circularError = importChain.push(absoluteUrl);
82
+ if (circularError) {
83
+ return { success: false, error: circularError };
84
+ }
85
+ try {
86
+ const cached = this.cache.get(absoluteUrl);
87
+ if (cached) {
88
+ return { success: true, data: cached };
89
+ }
90
+ const loadResult = await this.fetchSchema(absoluteUrl);
91
+ if (!loadResult.success) {
92
+ return loadResult;
93
+ }
94
+ const loaded = {
95
+ schema: loadResult.data,
96
+ sourcePath: absoluteUrl,
97
+ importPath
98
+ };
99
+ this.cache.set(absoluteUrl, loaded);
100
+ return { success: true, data: loaded };
101
+ } finally {
102
+ importChain.pop();
103
+ }
104
+ }
105
+ /**
106
+ * Load a specific orbital from a schema by name.
107
+ */
108
+ async loadOrbital(importPath, orbitalName, fromPath, chain) {
109
+ const schemaResult = await this.load(importPath, fromPath, chain);
110
+ if (!schemaResult.success) {
111
+ return schemaResult;
112
+ }
113
+ const schema = schemaResult.data.schema;
114
+ let orbital;
115
+ if (orbitalName) {
116
+ const found = schema.orbitals.find(
117
+ (o) => o.name === orbitalName
118
+ );
119
+ if (!found) {
120
+ return {
121
+ success: false,
122
+ error: `Orbital "${orbitalName}" not found in ${importPath}. Available: ${schema.orbitals.map((o) => o.name).join(", ")}`
123
+ };
124
+ }
125
+ orbital = found;
126
+ } else {
127
+ if (schema.orbitals.length === 0) {
128
+ return {
129
+ success: false,
130
+ error: `No orbitals found in ${importPath}`
131
+ };
132
+ }
133
+ orbital = schema.orbitals[0];
134
+ }
135
+ return {
136
+ success: true,
137
+ data: {
138
+ orbital,
139
+ orbitals: schema.orbitals,
140
+ ...schema.config ? { schemaConfig: schema.config } : {},
141
+ sourcePath: schemaResult.data.sourcePath,
142
+ importPath
143
+ }
144
+ };
145
+ }
146
+ /**
147
+ * Resolve an import path to an absolute URL.
148
+ */
149
+ resolvePath(importPath, fromPath) {
150
+ if (importPath.startsWith("http://") || importPath.startsWith("https://")) {
151
+ return { success: true, data: importPath };
152
+ }
153
+ if (importPath.startsWith("std/")) {
154
+ return this.resolveStdPath(importPath);
155
+ }
156
+ if (importPath.startsWith("@")) {
157
+ return this.resolveScopedPath(importPath);
158
+ }
159
+ if (importPath.startsWith("./") || importPath.startsWith("../")) {
160
+ return this.resolveRelativePath(importPath, fromPath);
161
+ }
162
+ return this.resolveRelativePath(`./${importPath}`, fromPath);
163
+ }
164
+ /**
165
+ * Resolve a standard library path.
166
+ */
167
+ resolveStdPath(importPath) {
168
+ if (!this.options.stdLibPath) {
169
+ return {
170
+ success: false,
171
+ error: `Standard library URL not configured. Cannot load: ${importPath}`
172
+ };
173
+ }
174
+ const relativePath = importPath.slice(4);
175
+ let absoluteUrl = this.joinUrl(this.options.stdLibPath, relativePath);
176
+ if (!absoluteUrl.endsWith(".orb")) {
177
+ absoluteUrl += ".orb";
178
+ }
179
+ return { success: true, data: absoluteUrl };
180
+ }
181
+ /**
182
+ * Resolve a scoped package path.
183
+ */
184
+ resolveScopedPath(importPath) {
185
+ const match = importPath.match(/^(@[^/]+)/);
186
+ if (!match) {
187
+ return {
188
+ success: false,
189
+ error: `Invalid scoped package path: ${importPath}`
190
+ };
191
+ }
192
+ const scope = match[1];
193
+ const scopeRoot = this.options.scopedPaths[scope];
194
+ if (!scopeRoot) {
195
+ return {
196
+ success: false,
197
+ error: `Scoped package "${scope}" not configured. Available: ${Object.keys(this.options.scopedPaths).join(", ") || "none"}`
198
+ };
199
+ }
200
+ const relativePath = importPath.slice(scope.length + 1);
201
+ let absoluteUrl = this.joinUrl(scopeRoot, relativePath);
202
+ if (!absoluteUrl.endsWith(".orb")) {
203
+ absoluteUrl += ".orb";
204
+ }
205
+ return { success: true, data: absoluteUrl };
206
+ }
207
+ /**
208
+ * Resolve a relative path.
209
+ */
210
+ resolveRelativePath(importPath, fromPath) {
211
+ const baseUrl = fromPath ? this.getParentUrl(fromPath) : this.options.basePath;
212
+ let absoluteUrl = this.joinUrl(baseUrl, importPath);
213
+ if (!absoluteUrl.endsWith(".orb")) {
214
+ absoluteUrl += ".orb";
215
+ }
216
+ return { success: true, data: absoluteUrl };
217
+ }
218
+ /**
219
+ * Fetch and parse an OrbitalSchema from a URL.
220
+ */
221
+ async fetchSchema(url) {
222
+ try {
223
+ const controller = new AbortController();
224
+ const timeoutId = setTimeout(
225
+ () => controller.abort(),
226
+ this.options.timeout
227
+ );
228
+ try {
229
+ const response = await fetch(url, {
230
+ ...this.options.fetchOptions,
231
+ credentials: this.options.credentials,
232
+ signal: controller.signal,
233
+ headers: {
234
+ Accept: "application/json",
235
+ ...this.options.fetchOptions?.headers
236
+ }
237
+ });
238
+ if (!response.ok) {
239
+ return {
240
+ success: false,
241
+ error: `HTTP ${response.status}: ${response.statusText} for ${url}`
242
+ };
243
+ }
244
+ const text = await response.text();
245
+ let data;
246
+ try {
247
+ data = JSON.parse(text);
248
+ } catch (e) {
249
+ return {
250
+ success: false,
251
+ error: `Invalid JSON in ${url}: ${e instanceof Error ? e.message : String(e)}`
252
+ };
253
+ }
254
+ const parseResult = OrbitalSchemaSchema.safeParse(data);
255
+ if (!parseResult.success) {
256
+ const errors = parseResult.error.issues.map((e) => ` - ${e.path.map(String).join(".")}: ${e.message}`).join("\n");
257
+ return {
258
+ success: false,
259
+ error: `Invalid schema in ${url}:
260
+ ${errors}`
261
+ };
262
+ }
263
+ return { success: true, data: parseResult.data };
264
+ } finally {
265
+ clearTimeout(timeoutId);
266
+ }
267
+ } catch (e) {
268
+ if (e instanceof Error && e.name === "AbortError") {
269
+ return {
270
+ success: false,
271
+ error: `Request timeout for ${url} (${this.options.timeout}ms)`
272
+ };
273
+ }
274
+ return {
275
+ success: false,
276
+ error: `Failed to fetch ${url}: ${e instanceof Error ? e.message : String(e)}`
277
+ };
278
+ }
279
+ }
280
+ /**
281
+ * Join URL parts, handling relative paths and trailing slashes.
282
+ */
283
+ joinUrl(base, path) {
284
+ if (path.startsWith("http://") || path.startsWith("https://")) {
285
+ return path;
286
+ }
287
+ if (isAbsoluteUrl(base)) return new URL(path, base.endsWith("/") ? base : base + "/").href;
288
+ const normalizedBase = base.endsWith("/") ? base.slice(0, -1) : base;
289
+ const normalizedPath = path.startsWith("/") ? path : "/" + path;
290
+ if (normalizedPath.startsWith("/./")) {
291
+ return normalizedBase + normalizedPath.slice(2);
292
+ }
293
+ if (normalizedPath.startsWith("/../")) {
294
+ const baseParts = normalizedBase.split("/");
295
+ baseParts.pop();
296
+ return baseParts.join("/") + normalizedPath.slice(3);
297
+ }
298
+ return normalizedBase + normalizedPath;
299
+ }
300
+ /**
301
+ * Get parent URL (directory) from a URL.
302
+ */
303
+ getParentUrl(url) {
304
+ if (isAbsoluteUrl(url)) {
305
+ const urlObj = new URL(url);
306
+ const pathParts = urlObj.pathname.split("/");
307
+ pathParts.pop();
308
+ urlObj.pathname = pathParts.join("/");
309
+ return urlObj.href;
310
+ }
311
+ const lastSlash = url.lastIndexOf("/");
312
+ return lastSlash !== -1 ? url.slice(0, lastSlash) : url;
313
+ }
314
+ /**
315
+ * Clear the cache.
316
+ */
317
+ clearCache() {
318
+ this.cache.clear();
319
+ }
320
+ /**
321
+ * Get cache statistics.
322
+ */
323
+ getCacheStats() {
324
+ return { size: this.cache.size };
325
+ }
326
+ };
327
+ function createHttpLoader(basePath, options) {
328
+ return new HttpLoader({
329
+ basePath,
330
+ ...options
331
+ });
332
+ }
333
+
334
+ export { HttpImportChain, HttpLoader, createHttpLoader };