@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 @@
1
+
@@ -0,0 +1,63 @@
1
+ // src/runtime/effects/composition/layout-strategy.ts
2
+ function hasSequentialChain(wiring) {
3
+ if (wiring.length < 2) {
4
+ return false;
5
+ }
6
+ const adjacency = /* @__PURE__ */ new Map();
7
+ const allTargets = /* @__PURE__ */ new Set();
8
+ for (const entry of wiring) {
9
+ let targets = adjacency.get(entry.from);
10
+ if (!targets) {
11
+ targets = /* @__PURE__ */ new Set();
12
+ adjacency.set(entry.from, targets);
13
+ }
14
+ targets.add(entry.to);
15
+ allTargets.add(entry.to);
16
+ }
17
+ const roots = [];
18
+ for (const from of adjacency.keys()) {
19
+ if (!allTargets.has(from)) {
20
+ roots.push(from);
21
+ }
22
+ }
23
+ const starts = roots.length > 0 ? roots : [...adjacency.keys()];
24
+ for (const start of starts) {
25
+ let current = start;
26
+ let length = 1;
27
+ const visited = /* @__PURE__ */ new Set([current]);
28
+ while (true) {
29
+ const nexts = adjacency.get(current);
30
+ if (!nexts || nexts.size === 0) break;
31
+ let advanced = false;
32
+ for (const next of nexts) {
33
+ if (!visited.has(next)) {
34
+ visited.add(next);
35
+ current = next;
36
+ length++;
37
+ advanced = true;
38
+ break;
39
+ }
40
+ }
41
+ if (!advanced) break;
42
+ }
43
+ if (length >= 3) {
44
+ return true;
45
+ }
46
+ }
47
+ return false;
48
+ }
49
+ function detectLayoutStrategy(orbitals, eventWiring) {
50
+ if (eventWiring && eventWiring.length > 0 && hasSequentialChain(eventWiring)) {
51
+ return "wizard-flow";
52
+ }
53
+ const count = orbitals.length;
54
+ if (count <= 1) {
55
+ return "single";
56
+ }
57
+ if (count <= 4) {
58
+ return "tabs";
59
+ }
60
+ return "sidebar";
61
+ }
62
+
63
+ export { detectLayoutStrategy };
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,10 @@
1
+ // src/runtime/effects/composition/pipe.ts
2
+ function pipeBehaviors(seed, ...steps) {
3
+ let current = seed;
4
+ for (const step of steps) {
5
+ current = step(current);
6
+ }
7
+ return current;
8
+ }
9
+
10
+ export { pipeBehaviors };
@@ -0,0 +1,48 @@
1
+ // src/effects/on-device-model.ts
2
+ var NO_ON_DEVICE_MODEL = "browser/prompt: no on-device model is wired into this host";
3
+ var NO_ON_DEVICE_EMBEDDER = "browser/embed: no on-device embedder is wired into this host";
4
+ var OnDeviceModelFailure = class extends Error {
5
+ kind;
6
+ payload;
7
+ constructor(kind, message, key) {
8
+ super(message);
9
+ this.name = "OnDeviceModelFailure";
10
+ this.kind = kind;
11
+ this.payload = { error: message, kind, key };
12
+ }
13
+ };
14
+ function failureMessage(error) {
15
+ return error instanceof Error ? error.message : String(error);
16
+ }
17
+ async function promptOnDevice(ports, text, schemaText, key, signal) {
18
+ const model = ports?.model;
19
+ if (model === void 0) throw new OnDeviceModelFailure("unconfigured", NO_ON_DEVICE_MODEL, key);
20
+ let schema;
21
+ try {
22
+ const parsed = JSON.parse(schemaText);
23
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new Error("not an object");
24
+ schema = parsed;
25
+ } catch {
26
+ throw new OnDeviceModelFailure("failed", "browser/prompt: the response schema must be JSON Schema text: a JSON object", key);
27
+ }
28
+ try {
29
+ const state = await model.availability();
30
+ if (state !== "available") throw new OnDeviceModelFailure("unavailable", `The on-device model is ${state}`, key);
31
+ return await model.prompt(text, schema, signal);
32
+ } catch (error) {
33
+ if (error instanceof OnDeviceModelFailure) throw error;
34
+ throw new OnDeviceModelFailure("failed", failureMessage(error), key);
35
+ }
36
+ }
37
+ async function embedOnDevice(ports, texts, key, signal) {
38
+ if (texts.length === 0) return [];
39
+ const embedder = ports?.embedder;
40
+ if (embedder === void 0) throw new OnDeviceModelFailure("unconfigured", NO_ON_DEVICE_EMBEDDER, key);
41
+ try {
42
+ return await embedder.embed([...texts], signal);
43
+ } catch (error) {
44
+ throw new OnDeviceModelFailure("failed", failureMessage(error), key);
45
+ }
46
+ }
47
+
48
+ export { NO_ON_DEVICE_EMBEDDER, NO_ON_DEVICE_MODEL, OnDeviceModelFailure, embedOnDevice, promptOnDevice };
@@ -0,0 +1,55 @@
1
+ // src/client/awaiting.ts
2
+ var AwaitingRegistry = class {
3
+ entries = /* @__PURE__ */ new Map();
4
+ listeners = /* @__PURE__ */ new Map();
5
+ anyListeners = /* @__PURE__ */ new Set();
6
+ version = 0;
7
+ begin(list) {
8
+ for (const entry of list) {
9
+ this.entries.set(entry.trait, entry);
10
+ this.emit(entry.trait);
11
+ }
12
+ }
13
+ end(traits) {
14
+ for (const trait of traits) {
15
+ if (!this.entries.delete(trait)) continue;
16
+ this.emit(trait);
17
+ }
18
+ }
19
+ get(trait) {
20
+ return this.entries.get(trait);
21
+ }
22
+ list() {
23
+ return [...this.entries.values()];
24
+ }
25
+ subscribe(trait, listener) {
26
+ let set = this.listeners.get(trait);
27
+ if (!set) {
28
+ set = /* @__PURE__ */ new Set();
29
+ this.listeners.set(trait, set);
30
+ }
31
+ set.add(listener);
32
+ return () => {
33
+ set?.delete(listener);
34
+ if (set && set.size === 0) this.listeners.delete(trait);
35
+ };
36
+ }
37
+ /** Any trait's awaiting change (an empty slot does not know which trait will fill it). */
38
+ subscribeAll(listener) {
39
+ this.anyListeners.add(listener);
40
+ return () => {
41
+ this.anyListeners.delete(listener);
42
+ };
43
+ }
44
+ /** Bumped on every change — a stable snapshot key for `useSyncExternalStore`. */
45
+ getVersion() {
46
+ return this.version;
47
+ }
48
+ emit(trait) {
49
+ this.version += 1;
50
+ this.listeners.get(trait)?.forEach((listener) => listener());
51
+ this.anyListeners.forEach((listener) => listener());
52
+ }
53
+ };
54
+
55
+ export { AwaitingRegistry };
@@ -0,0 +1,48 @@
1
+ // src/credentials/scope.ts
2
+ function credentialModeFromEnv(env) {
3
+ return env.ALMADAR_INTEGRATIONS_MODE === "mock" || env.USE_MOCK_DATA === "true" ? "mock" : "real";
4
+ }
5
+ var installedStore = null;
6
+ var modeControl = null;
7
+ var tenantScope;
8
+ function installCredentialScopeStorage(storage) {
9
+ tenantScope = storage;
10
+ }
11
+ function runWithCredentialScope(store, fn) {
12
+ if (tenantScope === void 0) throw new Error("runWithCredentialScope needs an installed CredentialScopeStorage (a Node host installs it through @almadar/shell-node)");
13
+ return tenantScope.run(store, fn);
14
+ }
15
+ function installModeControl(control) {
16
+ modeControl = control;
17
+ }
18
+ function getModeControl() {
19
+ return modeControl;
20
+ }
21
+ function installCredentialStore(store) {
22
+ installedStore = store;
23
+ }
24
+ function getInstalledCredentialStore() {
25
+ return installedStore;
26
+ }
27
+ function getEffectiveCredentialStore() {
28
+ return tenantScope?.getStore() ?? installedStore;
29
+ }
30
+ function uninstallCredentialStore() {
31
+ installedStore = null;
32
+ }
33
+ var CREDENTIALS_SOURCE_ENV = "ALMADAR_CREDENTIALS_SOURCE";
34
+ var HOST_SETTING_VARS = /* @__PURE__ */ new Set(["ALMADAR_CREDENTIAL_ADMIN_ROLES", CREDENTIALS_SOURCE_ENV, "ALMADAR_INTEGRATIONS_MODE", "USE_MOCK_DATA"]);
35
+ function credentialsFromStoreOnly(env) {
36
+ return env[CREDENTIALS_SOURCE_ENV] === "store";
37
+ }
38
+ function resolveCredentialRef(ref, env = typeof process === "undefined" ? {} : process.env, principal) {
39
+ const tenant = tenantScope?.getStore();
40
+ if (tenant) return tenant.resolve(ref, principal);
41
+ if (principal !== void 0) return installedStore?.resolve(ref, principal);
42
+ const stored = installedStore?.resolve(ref);
43
+ if (stored !== void 0) return stored;
44
+ if (credentialsFromStoreOnly(env) && !HOST_SETTING_VARS.has(ref)) return void 0;
45
+ return env[ref];
46
+ }
47
+
48
+ export { CREDENTIALS_SOURCE_ENV, credentialModeFromEnv, credentialsFromStoreOnly, getEffectiveCredentialStore, getInstalledCredentialStore, getModeControl, installCredentialScopeStorage, installCredentialStore, installModeControl, resolveCredentialRef, runWithCredentialScope, uninstallCredentialStore };
@@ -0,0 +1,135 @@
1
+ import { eventPayloadOf, isInlineTrait, normalizeCallSiteConfigToValues, JsonValueSchema, isJsonObject, EntityRowSchema, orbitalInlineEntities } from '@almadar/core';
2
+ import { ownerFieldsFromSchema } from '@almadar/core/mock';
3
+
4
+ // src/runtime/entities/std-mock-seed.ts
5
+ var SEED_ORBITAL = "MockSeedOrbital";
6
+ var SEED_TRAIT = "MockSeed";
7
+ function asJson(value) {
8
+ return JsonValueSchema.parse(JSON.parse(JSON.stringify(value)));
9
+ }
10
+ function fieldOf(value, name, what) {
11
+ if (value === void 0 || !isJsonObject(value)) throw new Error(`std-mock-seed: ${what} is not an object`);
12
+ const found = value[name];
13
+ if (found === void 0) throw new Error(`std-mock-seed: ${what} has no ${name}`);
14
+ return found;
15
+ }
16
+ function textOf(value, what) {
17
+ if (typeof value !== "string") throw new Error(`std-mock-seed: ${what} is not a string`);
18
+ return value;
19
+ }
20
+ function cellOf(value) {
21
+ return {
22
+ store: textOf(fieldOf(value, "store", "owner cell"), "cell store"),
23
+ id: textOf(fieldOf(value, "id", "owner cell"), "cell id"),
24
+ column: textOf(fieldOf(value, "column", "owner cell"), "cell column")
25
+ };
26
+ }
27
+ function cellsOf(value, what) {
28
+ if (!Array.isArray(value)) throw new Error(`std-mock-seed: ${what} is not an array`);
29
+ return value.map(cellOf);
30
+ }
31
+ function journalOf(value) {
32
+ return {
33
+ viewerId: textOf(fieldOf(value, "viewerId", "journal"), "journal viewerId"),
34
+ stamped: cellsOf(fieldOf(value, "stamped", "journal"), "journal stamped"),
35
+ deferred: cellsOf(fieldOf(value, "deferred", "journal"), "journal deferred")
36
+ };
37
+ }
38
+ function changeOf(value) {
39
+ const kind = fieldOf(value, "kind", "owner change");
40
+ if (kind !== "set" && kind !== "rekey") throw new Error("std-mock-seed: owner change kind is neither set nor rekey");
41
+ return { ...cellOf(value), kind, ownerId: textOf(fieldOf(value, "ownerId", "owner change"), "change ownerId") };
42
+ }
43
+ function storesOf(value) {
44
+ if (!isJsonObject(value)) throw new Error("std-mock-seed: dataset stores is not an object");
45
+ return Object.fromEntries(Object.entries(value).map(([store, rows]) => [store, EntityRowSchema.array().parse(rows)]));
46
+ }
47
+ function ownerPairsOf(schema) {
48
+ return ownerFieldsFromSchema(schema).map((field) => {
49
+ const dot = field.indexOf(".");
50
+ if (dot <= 0 || dot === field.length - 1) throw new Error(`std-mock-seed: owner field ${field} is not Entity.column`);
51
+ return { entity: field.slice(0, dot), column: field.slice(dot + 1) };
52
+ });
53
+ }
54
+ var StdMockSeed = class {
55
+ constructor(engine, config, user) {
56
+ this.engine = engine;
57
+ this.config = config;
58
+ this.user = user;
59
+ }
60
+ engine;
61
+ config;
62
+ user;
63
+ async ask(event, payload, done) {
64
+ const response = await this.engine.evaluate(
65
+ SEED_ORBITAL,
66
+ { event, targetTrait: SEED_TRAIT, payload: eventPayloadOf(asJson(payload)) },
67
+ { orbital: SEED_ORBITAL, ...this.user !== void 0 ? { user: this.user } : {} }
68
+ );
69
+ const failed = response.emittedEvents.find((emitted) => emitted.event === "DATASET_FAILED");
70
+ if (failed !== void 0) throw new Error(`std-mock-seed: ${event} refused: ${JSON.stringify(failed.payload ?? {})}`);
71
+ const answer = response.emittedEvents.find((emitted) => emitted.event === done);
72
+ if (answer === void 0) throw new Error(`std-mock-seed: ${event} did not answer ${done}`);
73
+ return asJson(answer.payload ?? {});
74
+ }
75
+ /** Sample the program's dataset (`DATASET_INPUT`). */
76
+ async dataset(program, run) {
77
+ const done = await this.ask("DATASET_INPUT", {
78
+ program,
79
+ count: this.config.count,
80
+ seed: this.config.seed,
81
+ nowMs: run.nowMs,
82
+ viewerId: run.viewerId ?? "",
83
+ ownerPairs: ownerPairsOf(program),
84
+ ...run.locale !== void 0 ? { locale: run.locale } : {}
85
+ }, "DATASET_DONE");
86
+ return { stores: storesOf(fieldOf(done, "stores", "DATASET_DONE")), journal: journalOf(fieldOf(done, "journal", "DATASET_DONE")) };
87
+ }
88
+ /**
89
+ * Re-point the dataset's tracked owner cells at `viewer` (`RESTAMP_INPUT`); `stores` are the current authoritative rows.
90
+ * `firstOwner` marks the stamp right after seeding; a persona switch restamps only when the program's
91
+ * `restampOnPersona` config says so, otherwise it answers no changes.
92
+ */
93
+ async restamp(program, stores, journal, viewer, firstOwner) {
94
+ const done = await this.ask("RESTAMP_INPUT", { program, stores, journal, viewer, firstOwner, restampOnPersona: this.config.restampOnPersona }, "RESTAMP_DONE");
95
+ const changes = fieldOf(done, "changes", "RESTAMP_DONE");
96
+ if (!Array.isArray(changes)) throw new Error("std-mock-seed: RESTAMP_DONE changes is not an array");
97
+ return { journal: journalOf(fieldOf(done, "journal", "RESTAMP_DONE")), changes: changes.map(changeOf) };
98
+ }
99
+ };
100
+ var STD_MOCK_SEED_SOURCE = "std/behaviors/std-mock-seed";
101
+ var SEED_TRAIT_REF = "traits.MockSeed";
102
+ function declaredValue(values, key, is) {
103
+ const value = values[key];
104
+ if (value === void 0 || !is(value)) throw new Error(`std-mock-seed: config ${key} is not declared as expected`);
105
+ return value;
106
+ }
107
+ function declaredSeedConfig(seedProgram, app) {
108
+ const seedTrait = seedProgram.orbitals.flatMap((orbital) => orbital.traits ?? []).find((t) => isInlineTrait(t) && t.name === SEED_TRAIT);
109
+ if (seedTrait === void 0 || !isInlineTrait(seedTrait)) throw new Error(`std-mock-seed: the seed program has no ${SEED_TRAIT} trait`);
110
+ const composed = (app?.orbitals ?? []).flatMap((orbital) => {
111
+ const aliases = (orbital.uses ?? []).filter((u) => u.from === STD_MOCK_SEED_SOURCE).map((u) => u.as);
112
+ return (orbital.traits ?? []).flatMap((t) => typeof t !== "string" && !isInlineTrait(t) && aliases.some((alias) => t.ref === `${alias}.${SEED_TRAIT_REF}`) ? [normalizeCallSiteConfigToValues(t.config) ?? {}] : []);
113
+ });
114
+ const values = Object.assign({}, normalizeCallSiteConfigToValues(seedTrait.config) ?? {}, ...composed);
115
+ return {
116
+ count: declaredValue(values, "count", (v) => typeof v === "number"),
117
+ seed: declaredValue(values, "seed", (v) => typeof v === "number"),
118
+ defaultPersona: declaredValue(values, "defaultPersona", (v) => typeof v === "string"),
119
+ restampOnPersona: declaredValue(values, "restampOnPersona", (v) => typeof v === "boolean")
120
+ };
121
+ }
122
+ function entityByStore(program) {
123
+ const byStore = /* @__PURE__ */ new Map();
124
+ for (const entity of program.orbitals.flatMap(orbitalInlineEntities)) {
125
+ if (entity.collection !== void 0 && entity.collection !== "") byStore.set(entity.collection, entity.name);
126
+ }
127
+ return byStore;
128
+ }
129
+ async function readSeededStores(persistence, program) {
130
+ const stores = {};
131
+ for (const [store, entityType] of entityByStore(program)) stores[store] = await persistence.list(entityType);
132
+ return stores;
133
+ }
134
+
135
+ export { StdMockSeed, declaredSeedConfig, readSeededStores };
@@ -0,0 +1,19 @@
1
+ // src/kernel/program-effects.ts
2
+ var PROGRAM_EFFECTS = [
3
+ "behavior/catalog",
4
+ "behavior/describe",
5
+ "behavior/source",
6
+ "behavior/resolve",
7
+ "behavior/dependencies",
8
+ "program/read",
9
+ "program/print",
10
+ "program/eval",
11
+ "program/validate",
12
+ "program/compose",
13
+ "program/step"
14
+ ];
15
+ function isProgramEffect(name) {
16
+ return PROGRAM_EFFECTS.includes(name);
17
+ }
18
+
19
+ export { PROGRAM_EFFECTS, isProgramEffect };
@@ -0,0 +1,62 @@
1
+ // src/runtime/events/identity/routing.ts
2
+ function eventRouteKey(eventName, eventId) {
3
+ return eventId ? `@evt:${eventId}` : eventName;
4
+ }
5
+ function buildSourceMatcher(src, listenerOrbital) {
6
+ if (src.kind === "any") return () => true;
7
+ if (src.kind === "trait") {
8
+ if (src.traitId !== void 0) {
9
+ const wantedTraitId = src.traitId;
10
+ return (source) => !!source && source.traitId === wantedTraitId;
11
+ }
12
+ const wantedTrait2 = src.trait;
13
+ return (source) => !!source && source.orbital === listenerOrbital && source.trait === wantedTrait2;
14
+ }
15
+ if (src.orbitalId !== void 0 && src.traitId !== void 0) {
16
+ const wantedOrbitalId = src.orbitalId;
17
+ const wantedTraitId = src.traitId;
18
+ return (source) => !!source && source.orbitalId === wantedOrbitalId && source.traitId === wantedTraitId;
19
+ }
20
+ const wantedOrbital = src.orbital;
21
+ const wantedTrait = src.trait;
22
+ return (source) => !!source && source.orbital === wantedOrbital && source.trait === wantedTrait;
23
+ }
24
+ function parseListenSource(listener, listenerOrbital) {
25
+ const explicit = listener.source;
26
+ if (explicit && typeof explicit === "object") {
27
+ return {
28
+ bareEvent: listener.event,
29
+ matcher: buildSourceMatcher(explicit, listenerOrbital)
30
+ };
31
+ }
32
+ const key = listener.event;
33
+ const parts = key.split(".");
34
+ if (parts.length === 1) {
35
+ return { bareEvent: key, matcher: () => true };
36
+ }
37
+ if (parts.length === 2) {
38
+ const [sourceOrStar, eventName] = parts;
39
+ if (sourceOrStar === "*") {
40
+ return { bareEvent: eventName, matcher: () => true };
41
+ }
42
+ return {
43
+ bareEvent: eventName,
44
+ matcher: buildSourceMatcher(
45
+ { kind: "trait", trait: sourceOrStar },
46
+ listenerOrbital
47
+ )
48
+ };
49
+ }
50
+ if (parts.length >= 3) {
51
+ const eventName = parts[parts.length - 1];
52
+ const trait = parts[parts.length - 2];
53
+ const orbital = parts.slice(0, parts.length - 2).join(".");
54
+ return {
55
+ bareEvent: eventName,
56
+ matcher: buildSourceMatcher({ kind: "orbital", orbital, trait }, listenerOrbital)
57
+ };
58
+ }
59
+ return { bareEvent: key, matcher: () => true };
60
+ }
61
+
62
+ export { buildSourceMatcher, eventRouteKey, parseListenSource };
@@ -0,0 +1,15 @@
1
+ // src/client/trait-mount-error.ts
2
+ var TraitMountError = class extends Error {
3
+ trait;
4
+ event;
5
+ original;
6
+ constructor(trait, event, original) {
7
+ super(original.message);
8
+ this.name = "TraitMountError";
9
+ this.trait = trait;
10
+ this.event = event;
11
+ this.original = original;
12
+ }
13
+ };
14
+
15
+ export { TraitMountError };
@@ -0,0 +1,35 @@
1
+ import { readSeededStores } from './chunk-HMK6YMQS.js';
2
+ import { orbitalInlineEntities, personaFromIdentityRow } from '@almadar/core';
3
+ import { identityEntitiesOf } from '@almadar/core/mock';
4
+ import { createLogger } from '@almadar/logger';
5
+
6
+ var log = createLogger("almadar:shell-web:mock-seed");
7
+ function bindDeclaredCollections(store, entities) {
8
+ for (const entity of entities) {
9
+ if (entity.name && entity.collection && entity.browser !== true && entity.persistence !== "runtime") {
10
+ store.bindCollection?.(entity.name, entity.collection);
11
+ }
12
+ }
13
+ }
14
+ async function seedMockStore(host, schema, viewer) {
15
+ bindDeclaredCollections(host.persistence, schema.orbitals.flatMap(orbitalInlineEntities));
16
+ const named = viewer.namedByHost ? viewer.current() : void 0;
17
+ const dataset = await host.seeder.dataset(schema, { nowMs: host.nowMs, ...named !== void 0 ? { viewerId: named.id } : {} });
18
+ if (viewer.namedByHost) return { viewer: named, journal: dataset.journal };
19
+ const declared = host.seeder.config.defaultPersona;
20
+ if (declared === "") return { viewer: void 0, journal: dataset.journal };
21
+ const identity = identityEntitiesOf(schema.orbitals)[0];
22
+ const row = identity?.collection !== void 0 ? (dataset.stores[identity.collection] ?? []).find((r) => r.id === declared) : void 0;
23
+ const resolved = row === void 0 ? void 0 : personaFromIdentityRow(row);
24
+ if (resolved === void 0) throw new Error(`std-mock-seed: defaultPersona ${declared} names no ${identity?.name ?? "identity"} row of the seeded dataset`);
25
+ const restamp = await host.seeder.restamp(schema, dataset.stores, dataset.journal, resolved, true);
26
+ log.debug("seeded", { identity: identity?.name, viewer: resolved.id, changes: restamp.changes.length });
27
+ return { viewer: resolved, journal: restamp.journal };
28
+ }
29
+ async function restampMockOwner(host, schema, journal, user) {
30
+ const stores = await readSeededStores(host.persistence, schema);
31
+ const restamp = await host.seeder.restamp(schema, stores, journal, user, false);
32
+ return restamp.journal;
33
+ }
34
+
35
+ export { bindDeclaredCollections, restampMockOwner, seedMockStore };
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,54 @@
1
+ import { isInlineTrait } from '@almadar/core';
2
+
3
+ // src/runtime/effects/composition/event-wiring.ts
4
+ function findInlineTrait(orbitals, name) {
5
+ for (const orbital of orbitals) {
6
+ for (const traitRef of orbital.traits) {
7
+ if (isInlineTrait(traitRef) && traitRef.name === name) {
8
+ return traitRef;
9
+ }
10
+ }
11
+ }
12
+ return null;
13
+ }
14
+ function hasEmit(emits, event) {
15
+ return emits.some((e) => e.event === event);
16
+ }
17
+ function hasListen(listens, event, triggers) {
18
+ return listens.some((l) => l.event === event && l.triggers === triggers);
19
+ }
20
+ function applyEventWiring(orbitals, wiring) {
21
+ const cloned = JSON.parse(
22
+ JSON.stringify(orbitals)
23
+ );
24
+ for (const entry of wiring) {
25
+ const sourceTrait = findInlineTrait(cloned, entry.from);
26
+ if (sourceTrait) {
27
+ if (!sourceTrait.emits) {
28
+ sourceTrait.emits = [];
29
+ }
30
+ if (!hasEmit(sourceTrait.emits, entry.event)) {
31
+ sourceTrait.emits.push({
32
+ event: entry.event,
33
+ scope: "external"
34
+ });
35
+ }
36
+ }
37
+ const targetTrait = findInlineTrait(cloned, entry.to);
38
+ if (targetTrait) {
39
+ if (!targetTrait.listens) {
40
+ targetTrait.listens = [];
41
+ }
42
+ if (!hasListen(targetTrait.listens, entry.event, entry.triggers)) {
43
+ targetTrait.listens.push({
44
+ event: entry.event,
45
+ triggers: entry.triggers,
46
+ scope: "external"
47
+ });
48
+ }
49
+ }
50
+ }
51
+ return cloned;
52
+ }
53
+
54
+ export { applyEventWiring };
@@ -0,0 +1,7 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ export { __export };
@@ -0,0 +1,74 @@
1
+ // src/effects/in-flight-calls.ts
2
+ var InFlightCalls = class {
3
+ calls = /* @__PURE__ */ new Map();
4
+ /** Whether a call started with `key` is still running. */
5
+ inFlight(key) {
6
+ return (this.calls.get(key)?.size ?? 0) > 0;
7
+ }
8
+ /**
9
+ * Run `work` registered under `key`, handing it the abort signal; `work` must settle promptly once the
10
+ * signal aborts (see `untilAborted`). The call is cancelled when the signal was aborted by the time
11
+ * `work` settles, whatever it settled with.
12
+ */
13
+ async run(key, work) {
14
+ const lease = this.track(key);
15
+ try {
16
+ const value = await work(lease.signal);
17
+ return lease.signal.aborted ? { cancelled: true } : { cancelled: false, value };
18
+ } catch (err) {
19
+ if (lease.signal.aborted) return { cancelled: true };
20
+ throw err;
21
+ } finally {
22
+ lease.release();
23
+ }
24
+ }
25
+ reserve(key) {
26
+ return this.inFlight(key) ? void 0 : this.track(key);
27
+ }
28
+ track(key) {
29
+ const controller = new AbortController();
30
+ const running = this.calls.get(key) ?? /* @__PURE__ */ new Set();
31
+ running.add(controller);
32
+ this.calls.set(key, running);
33
+ return {
34
+ signal: controller.signal,
35
+ release: () => {
36
+ running.delete(controller);
37
+ if (running.size === 0 && this.calls.get(key) === running) this.calls.delete(key);
38
+ }
39
+ };
40
+ }
41
+ cancelAll() {
42
+ for (const key of this.calls.keys()) this.cancel(key);
43
+ }
44
+ /** Abort every call running under `key`; false (a no-op) when none is. */
45
+ cancel(key) {
46
+ const running = this.calls.get(key);
47
+ if (running === void 0 || running.size === 0) return false;
48
+ this.calls.delete(key);
49
+ for (const controller of running) controller.abort();
50
+ return true;
51
+ }
52
+ };
53
+ function untilAborted(signal, promise) {
54
+ if (signal.aborted) {
55
+ promise.catch(() => void 0);
56
+ return Promise.reject(new Error("The call was cancelled"));
57
+ }
58
+ return new Promise((resolve, reject) => {
59
+ const onAbort = () => reject(new Error("The call was cancelled"));
60
+ signal.addEventListener("abort", onAbort, { once: true });
61
+ promise.then(
62
+ (value) => {
63
+ signal.removeEventListener("abort", onAbort);
64
+ resolve(value);
65
+ },
66
+ (err) => {
67
+ signal.removeEventListener("abort", onAbort);
68
+ reject(err);
69
+ }
70
+ );
71
+ });
72
+ }
73
+
74
+ export { InFlightCalls, untilAborted };