@autonoma-ai/planner 0.1.9 → 0.1.10

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.
package/dist/index.js CHANGED
@@ -2160,25 +2160,6 @@ function resolveEntityOrder(models, importanceRank) {
2160
2160
  }
2161
2161
  return result;
2162
2162
  }
2163
- function getEntityDependencyChain(entityName, models, entityOrder) {
2164
- const modelMap = new Map(models.map((m) => [m.name, m]));
2165
- const visited = /* @__PURE__ */ new Set();
2166
- const chain = [];
2167
- function walk(name) {
2168
- if (visited.has(name)) return;
2169
- visited.add(name);
2170
- const model = modelMap.get(name);
2171
- if (!model) return;
2172
- for (const dep of model.created_by) {
2173
- if (entityOrder.includes(dep.owner)) {
2174
- walk(dep.owner);
2175
- }
2176
- }
2177
- chain.push(name);
2178
- }
2179
- walk(entityName);
2180
- return chain;
2181
- }
2182
2163
  var createdBySchema, auditedModelSchema, frontmatterSchema;
2183
2164
  var init_entity_order = __esm({
2184
2165
  "src/agents/04-recipe-builder/entity-order.ts"() {
@@ -3475,15 +3456,44 @@ var init_highlight = __esm({
3475
3456
  // src/agents/04-recipe-builder/recipe.ts
3476
3457
  import { readFile as readFile15, writeFile as writeFile7 } from "fs/promises";
3477
3458
  import { join as join22 } from "path";
3459
+ function collectRefs(value, out) {
3460
+ if (Array.isArray(value)) {
3461
+ for (const v of value) collectRefs(v, out);
3462
+ } else if (value !== null && typeof value === "object") {
3463
+ const obj = value;
3464
+ if (typeof obj._ref === "string") out.add(obj._ref);
3465
+ for (const v of Object.values(obj)) collectRefs(v, out);
3466
+ }
3467
+ }
3478
3468
  function buildSingleEntityRecipe(entityName, models, entityOrder, allEntities) {
3479
- const chain = getEntityDependencyChain(entityName, models, entityOrder);
3480
- const recipe = {};
3481
- for (const name of chain) {
3482
- const entity = allEntities[name];
3483
- if (entity?.recipeData && entity.recipeData.length > 0) {
3484
- recipe[name] = entity.recipeData;
3469
+ const modelMap = new Map(models.map((m) => [m.name, m]));
3470
+ const aliasOwner = /* @__PURE__ */ new Map();
3471
+ for (const [name, entity] of Object.entries(allEntities)) {
3472
+ for (const rec of entity?.recipeData ?? []) {
3473
+ if (typeof rec._alias === "string") aliasOwner.set(rec._alias, name);
3485
3474
  }
3486
3475
  }
3476
+ const recipe = {};
3477
+ const done = /* @__PURE__ */ new Set();
3478
+ const onStack = /* @__PURE__ */ new Set();
3479
+ function include(name) {
3480
+ if (done.has(name) || onStack.has(name)) return;
3481
+ onStack.add(name);
3482
+ const records = allEntities[name]?.recipeData ?? [];
3483
+ for (const dep of modelMap.get(name)?.created_by ?? []) {
3484
+ if (entityOrder.includes(dep.owner)) include(dep.owner);
3485
+ }
3486
+ const refs = /* @__PURE__ */ new Set();
3487
+ collectRefs(records, refs);
3488
+ for (const alias of refs) {
3489
+ const owner = aliasOwner.get(alias);
3490
+ if (owner && owner !== name) include(owner);
3491
+ }
3492
+ onStack.delete(name);
3493
+ done.add(name);
3494
+ if (records.length > 0) recipe[name] = records;
3495
+ }
3496
+ include(entityName);
3487
3497
  return recipe;
3488
3498
  }
3489
3499
  function buildFullRecipe(entityOrder, allEntities) {
@@ -3525,7 +3535,6 @@ var init_recipe = __esm({
3525
3535
  "src/agents/04-recipe-builder/recipe.ts"() {
3526
3536
  "use strict";
3527
3537
  init_esm_shims();
3528
- init_entity_order();
3529
3538
  RECIPE_FILE = "recipe.json";
3530
3539
  }
3531
3540
  });
@@ -3740,6 +3749,7 @@ ${completedAliases}
3740
3749
  Rules:
3741
3750
  - _alias fields must be unique identifiers (e.g., "card_1", "transaction_1")
3742
3751
  - _ref fields must reference an alias that ALREADY EXISTS on a parent entity \u2014 see the list of valid targets below. Never invent a _ref to an alias that isn't listed.
3752
+ - If the error says "references unknown alias(es): X", a _ref points at "X" but nothing being created declares it. Correct that _ref to one of the valid targets listed below (it's usually a typo, e.g. "users_1" vs "user_1"), or drop the reference if the field is optional. Do NOT leave a _ref pointing at an alias that isn't in the valid targets list.
3743
3753
  - Read scenarios.md to verify you're using correct alias names from parent entities
3744
3754
  - Field names must match the entity's schema from entity-audit.md`,
3745
3755
  model,