@almadar/core 4.7.0 → 4.8.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.
@@ -1,52 +1,8 @@
1
- import { T as TraitReference, a as TraitEventContract, E as Entity, S as SExpr, b as TraitEventListener, c as EntityField, d as EntityPersistence, e as EntityRow, U as UseDeclaration, f as EntityRef, g as TraitRef, P as PageRef, O as OrbitalDefinition, h as OrbitalSchema, i as Trait, j as Page, k as PageRefObject } from './schema-C-6fdZ5P.js';
2
- export { C as ComposeBehaviorsInput, a as ComposeBehaviorsResult, E as EventWiringEntry, L as LayoutStrategy, b as applyEventWiring, c as composeBehaviors, d as detectLayoutStrategy } from './compose-behaviors-BLEoAOk6.js';
1
+ import { T as TraitEventContract, E as Entity, S as SExpr, a as TraitEventListener, b as EntityField, c as EntityPersistence, d as EntityRow, U as UseDeclaration, e as EntityRef, f as TraitRef, P as PageRef, O as OrbitalDefinition, g as OrbitalSchema, h as Trait, i as Page, j as PageRefObject, k as TraitReference } from './schema-BCEjl1a1.js';
2
+ export { C as ComposeBehaviorsInput, a as ComposeBehaviorsResult, E as EventWiringEntry, L as LayoutStrategy, b as applyEventWiring, c as composeBehaviors, d as detectLayoutStrategy } from './compose-behaviors-aBzjGsxn.js';
3
3
  import 'zod';
4
4
  import '@almadar/patterns';
5
5
 
6
- /**
7
- * Explode Behavior Composition
8
- *
9
- * Human-authoring primitive (Phase 5.3 of Almadar_Agent_Behaviors_Plan).
10
- *
11
- * Reads a behavior's compiled `.orb` from the sibling `@almadar/std`
12
- * registry on disk and returns the flat list of `TraitReference` objects
13
- * it's composed from — each with `from`, `ref`, `linkedEntity`, and any
14
- * call-site overrides. **Not exposed to the agent or LLM.** The helper
15
- * exists for developers designing new molecules or debugging compositions.
16
- *
17
- * The function is Node-only. It walks the filesystem under
18
- * `packages/almadar-std/behaviors/registry/{atoms,molecules,organisms}/`
19
- * relative to this source file and will throw a descriptive error if the
20
- * behavior cannot be resolved.
21
- *
22
- * When the target is a leaf atom (no `uses:` / composition), the function
23
- * returns a single synthetic `TraitReference` pointing at the atom's own
24
- * inline trait so consumers always get something useful.
25
- *
26
- * @packageDocumentation
27
- */
28
-
29
- /**
30
- * Flatten a behavior's `.orb` composition into the list of
31
- * `TraitReference` objects it's built from.
32
- *
33
- * For composed behaviors (molecules, organisms) this returns every
34
- * `TraitReference` entry from every orbital's `traits:` array, carrying
35
- * the call-site `ref`, backfilled `from` (looked up against the orbital's
36
- * `uses:` imports when omitted), `linkedEntity`, `events`, `effects`, and
37
- * any other override fields declared at the call site.
38
- *
39
- * For leaf atoms (no composition, only an inline trait) the function
40
- * returns a single synthetic `TraitReference` pointing at the atom's own
41
- * trait, so consumers always get a non-empty array they can iterate.
42
- *
43
- * @param behaviorName - Registry name of the behavior (e.g. `"std-cart"`,
44
- * `"std-browse"`).
45
- * @returns Flat list of every `TraitReference` the behavior is composed of.
46
- * @throws Error when the behavior cannot be found in any registry level.
47
- */
48
- declare function explodeBehaviorComposition(behaviorName: string): TraitReference[];
49
-
50
6
  /**
51
7
  * Orbital Builders
52
8
  *
@@ -287,4 +243,4 @@ declare function compose(orbitals: (OrbitalDefinition | OrbitalSchema)[], pages:
287
243
  */
288
244
  declare function pipe(orbitals: (OrbitalDefinition | OrbitalSchema)[], events: TraitEventContract[], appName?: string): OrbitalSchema;
289
245
 
290
- export { type ComposeConnection, type ComposePage, type MakeAtomOrbitalOpts, type MakeAtomOrbitalTraitOverrides, type MakeEntityOpts, type MakeOrbitalWithUsesOpts, type MakePageOpts, type MakePageRefOpts, type MakeTraitRefOpts, compose, connect, ensureIdField, explodeBehaviorComposition, extractTrait, makeAtomOrbital, makeEntity, makeOrbital, makeOrbitalWithUses, makePage, makePageRef, makeSchema, makeTraitRef, mergeOrbitals, pipe, plural, wire };
246
+ export { type ComposeConnection, type ComposePage, type MakeAtomOrbitalOpts, type MakeAtomOrbitalTraitOverrides, type MakeEntityOpts, type MakeOrbitalWithUsesOpts, type MakePageOpts, type MakePageRefOpts, type MakeTraitRefOpts, compose, connect, ensureIdField, extractTrait, makeAtomOrbital, makeEntity, makeOrbital, makeOrbitalWithUses, makePage, makePageRef, makeSchema, makeTraitRef, mergeOrbitals, pipe, plural, wire };
package/dist/builders.js CHANGED
@@ -1,7 +1,4 @@
1
1
  import { z } from 'zod';
2
- import { readFileSync } from 'fs';
3
- import { resolve, dirname } from 'path';
4
- import { fileURLToPath } from 'url';
5
2
 
6
3
  // src/types/orbital.ts
7
4
  var FieldTypeSchema = z.enum([
@@ -1041,104 +1038,6 @@ function composeBehaviors(input) {
1041
1038
  }
1042
1039
  };
1043
1040
  }
1044
- function registryRoot() {
1045
- const here = dirname(fileURLToPath(import.meta.url));
1046
- return resolve(here, "..", "..", "..", "almadar-std", "behaviors", "registry");
1047
- }
1048
- var LEVELS = ["atoms", "molecules", "organisms"];
1049
- function resolveBehavior(behaviorName) {
1050
- const root = registryRoot();
1051
- const searched = [];
1052
- for (const level of LEVELS) {
1053
- const path = resolve(root, level, `${behaviorName}.orb`);
1054
- searched.push(path);
1055
- let source;
1056
- try {
1057
- source = readFileSync(path, "utf8");
1058
- } catch {
1059
- continue;
1060
- }
1061
- let parsed;
1062
- try {
1063
- parsed = JSON.parse(source);
1064
- } catch (err) {
1065
- const message = err instanceof Error ? err.message : String(err);
1066
- throw new Error(
1067
- `explodeBehaviorComposition: failed to parse ${path} as JSON: ${message}`
1068
- );
1069
- }
1070
- return { level, path, schema: parsed };
1071
- }
1072
- throw new Error(
1073
- `explodeBehaviorComposition: behavior "${behaviorName}" not found. Searched:
1074
- - ${searched.join("\n - ")}`
1075
- );
1076
- }
1077
- function isTraitReferenceObject(entry) {
1078
- return typeof entry === "object" && entry !== null && "ref" in entry && typeof entry.ref === "string" && !isInlineTrait(entry);
1079
- }
1080
- function aliasToFromMap(uses) {
1081
- const map = /* @__PURE__ */ new Map();
1082
- if (!uses) return map;
1083
- for (const use of uses) {
1084
- map.set(use.as, use.from);
1085
- }
1086
- return map;
1087
- }
1088
- function extractAlias(ref) {
1089
- const match = ref.match(/^([A-Z][a-zA-Z0-9]*)\.traits\.[A-Z][a-zA-Z0-9]*$/);
1090
- return match ? match[1] : null;
1091
- }
1092
- function findAtomInlineTrait(orbital) {
1093
- for (const entry of orbital.traits) {
1094
- if (typeof entry === "object" && entry !== null && isInlineTrait(entry)) {
1095
- return entry;
1096
- }
1097
- }
1098
- return void 0;
1099
- }
1100
- function syntheticLeafReference(behaviorName, orbital, trait) {
1101
- const base = behaviorName.replace(/^std-/, "");
1102
- const alias = base.split("-").filter((segment) => segment.length > 0).map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1)).join("") || "Behavior";
1103
- const entityName = typeof orbital.entity === "string" ? orbital.entity : "name" in orbital.entity && typeof orbital.entity.name === "string" ? orbital.entity.name : void 0;
1104
- const reference = {
1105
- ref: `${alias}.traits.${trait.name}`,
1106
- from: `std/behaviors/${behaviorName}`
1107
- };
1108
- if (trait.linkedEntity !== void 0) {
1109
- reference.linkedEntity = trait.linkedEntity;
1110
- } else if (entityName !== void 0) {
1111
- reference.linkedEntity = entityName;
1112
- }
1113
- return reference;
1114
- }
1115
- function explodeBehaviorComposition(behaviorName) {
1116
- const resolved = resolveBehavior(behaviorName);
1117
- const orbitals = Array.isArray(resolved.schema.orbitals) ? resolved.schema.orbitals : [];
1118
- const references = [];
1119
- for (const orbital of orbitals) {
1120
- const aliasMap = aliasToFromMap(orbital.uses);
1121
- for (const entry of orbital.traits ?? []) {
1122
- if (!isTraitReferenceObject(entry)) continue;
1123
- const copy = { ...entry };
1124
- if (copy.from === void 0) {
1125
- const alias = extractAlias(copy.ref);
1126
- const fromPath = alias !== null ? aliasMap.get(alias) : void 0;
1127
- if (fromPath !== void 0) {
1128
- copy.from = fromPath;
1129
- }
1130
- }
1131
- references.push(copy);
1132
- }
1133
- }
1134
- if (references.length > 0) return references;
1135
- const firstOrbital = orbitals[0];
1136
- const inlineTrait = firstOrbital ? findAtomInlineTrait(firstOrbital) : void 0;
1137
- if (firstOrbital && inlineTrait) {
1138
- return [syntheticLeafReference(behaviorName, firstOrbital, inlineTrait)];
1139
- }
1140
- return [];
1141
- }
1142
1041
 
1143
1042
  // src/builders.ts
1144
1043
  function ensureIdField(fields) {
@@ -1386,6 +1285,6 @@ function pipe(orbitals, events, appName) {
1386
1285
  };
1387
1286
  }
1388
1287
 
1389
- export { applyEventWiring, compose, composeBehaviors, connect, detectLayoutStrategy, ensureIdField, explodeBehaviorComposition, extractTrait, makeAtomOrbital, makeEntity, makeOrbital, makeOrbitalWithUses, makePage, makePageRef, makeSchema, makeTraitRef, mergeOrbitals, pipe, plural, wire };
1288
+ export { applyEventWiring, compose, composeBehaviors, connect, detectLayoutStrategy, ensureIdField, extractTrait, makeAtomOrbital, makeEntity, makeOrbital, makeOrbitalWithUses, makePage, makePageRef, makeSchema, makeTraitRef, mergeOrbitals, pipe, plural, wire };
1390
1289
  //# sourceMappingURL=builders.js.map
1391
1290
  //# sourceMappingURL=builders.js.map