@almadar/core 9.8.0 → 9.10.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.
package/dist/index.js CHANGED
@@ -1445,6 +1445,19 @@ var OrbitalConfigSchema = z.object({
1445
1445
  timeout: z.number().optional()
1446
1446
  }).optional()
1447
1447
  });
1448
+ var ConfigProvenanceRecordSchema = z.object({
1449
+ trait: z.string(),
1450
+ patternPath: z.string().optional(),
1451
+ prop: z.string(),
1452
+ knob: z.string()
1453
+ });
1454
+ var SchemaMetadataSchema = z.object({
1455
+ version: z.number().optional(),
1456
+ createdAt: z.number().optional(),
1457
+ source: z.string().optional(),
1458
+ updatedAt: z.number().optional(),
1459
+ configProvenance: z.record(z.array(ConfigProvenanceRecordSchema)).optional()
1460
+ });
1448
1461
  var OrbitalSchemaSchema = z.object({
1449
1462
  name: z.string().min(1, "Schema name is required"),
1450
1463
  description: z.string().optional(),
@@ -1456,7 +1469,8 @@ var OrbitalSchemaSchema = z.object({
1456
1469
  customPatterns: CustomPatternMapSchema,
1457
1470
  orbitals: z.array(OrbitalSchema).min(1, "At least one orbital is required"),
1458
1471
  services: z.array(ServiceDefinitionSchema).optional(),
1459
- config: OrbitalConfigSchema.optional()
1472
+ config: OrbitalConfigSchema.optional(),
1473
+ _metadata: SchemaMetadataSchema.optional()
1460
1474
  });
1461
1475
  function parseOrbitalSchema(data) {
1462
1476
  return OrbitalSchemaSchema.parse(data);
@@ -1897,6 +1911,182 @@ function widenTier(tier) {
1897
1911
  return tier;
1898
1912
  }
1899
1913
 
1914
+ // src/render-ui-edit.ts
1915
+ function navigatePatternPath(root, path) {
1916
+ if (!path || path === "root") return root;
1917
+ const parts = path.split(".");
1918
+ let current = root;
1919
+ for (const part of parts) {
1920
+ if (current === null || current === void 0 || typeof current !== "object") return null;
1921
+ if (Array.isArray(current)) {
1922
+ const idx = Number.parseInt(part, 10);
1923
+ if (Number.isNaN(idx) || idx < 0 || idx >= current.length) return null;
1924
+ current = current[idx];
1925
+ } else {
1926
+ const record = current;
1927
+ if (part === "children" && Array.isArray(record.children)) {
1928
+ current = record.children;
1929
+ } else {
1930
+ current = record[part];
1931
+ }
1932
+ }
1933
+ }
1934
+ return typeof current === "object" && current !== null && !Array.isArray(current) ? current : null;
1935
+ }
1936
+ function splitChildPath(path) {
1937
+ const lastDot = path.lastIndexOf(".");
1938
+ if (lastDot === -1) return null;
1939
+ const index = Number.parseInt(path.slice(lastDot + 1), 10);
1940
+ if (Number.isNaN(index)) return null;
1941
+ return { parentPath: path.slice(0, lastDot), index };
1942
+ }
1943
+ function setPropAtPath(root, path, prop, value) {
1944
+ const node = navigatePatternPath(root, path);
1945
+ if (!node) return false;
1946
+ node[prop] = value;
1947
+ return true;
1948
+ }
1949
+ function replaceChildAtPath(root, path, node) {
1950
+ const split = splitChildPath(path);
1951
+ if (!split) return false;
1952
+ const parent = navigatePatternPath(root, split.parentPath);
1953
+ if (!parent || !Array.isArray(parent.children)) return false;
1954
+ if (split.index < 0 || split.index >= parent.children.length) return false;
1955
+ parent.children[split.index] = node;
1956
+ return true;
1957
+ }
1958
+ function insertChildAtPath(root, parentPath, index, node) {
1959
+ const parent = navigatePatternPath(root, parentPath);
1960
+ if (!parent) return false;
1961
+ const children = parent.children ?? [];
1962
+ const i = index < 0 || index > children.length ? children.length : index;
1963
+ children.splice(i, 0, node);
1964
+ parent.children = children;
1965
+ return true;
1966
+ }
1967
+ function removeChildAtPath(root, path) {
1968
+ const split = splitChildPath(path);
1969
+ if (!split) return false;
1970
+ const parent = navigatePatternPath(root, split.parentPath);
1971
+ if (!parent || !Array.isArray(parent.children)) return false;
1972
+ if (split.index < 0 || split.index >= parent.children.length) return false;
1973
+ parent.children.splice(split.index, 1);
1974
+ return true;
1975
+ }
1976
+ function replaceNodeInPlace(target, source) {
1977
+ for (const key of Object.keys(target)) {
1978
+ delete target[key];
1979
+ }
1980
+ Object.assign(target, source);
1981
+ }
1982
+ function stableValue(value) {
1983
+ if (value === void 0) return "u";
1984
+ if (value === null) return "n";
1985
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1986
+ return JSON.stringify(value);
1987
+ }
1988
+ if (value instanceof Date) return value.toISOString();
1989
+ if (Array.isArray(value)) return `[${value.map(stableValue).join(",")}]`;
1990
+ const nodeType = "type" in value ? value.type : void 0;
1991
+ return `{${typeof nodeType === "string" ? nodeType : ""}}`;
1992
+ }
1993
+ function fingerprintNode(node) {
1994
+ const props = Object.keys(node).filter((k) => k !== "children").sort().map((k) => `${k}=${stableValue(node[k])}`).join(",");
1995
+ const childCount = Array.isArray(node.children) ? node.children.length : 0;
1996
+ return `t:${node.type ?? ""}|${props}|c:${childCount}`;
1997
+ }
1998
+ function findByFingerprint(node, path, fp) {
1999
+ if (fingerprintNode(node) === fp) return path;
2000
+ if (Array.isArray(node.children)) {
2001
+ for (let i = 0; i < node.children.length; i++) {
2002
+ const r = findByFingerprint(node.children[i], `${path}.children.${i}`, fp);
2003
+ if (r) return r;
2004
+ }
2005
+ }
2006
+ return null;
2007
+ }
2008
+ function readRenderUi(eff) {
2009
+ if (eff[0] !== "render-ui") return null;
2010
+ const slot = eff[1];
2011
+ const config = eff[2];
2012
+ if (typeof slot !== "string") return null;
2013
+ if (config === null || typeof config !== "object" || Array.isArray(config)) return null;
2014
+ return { slot, node: config };
2015
+ }
2016
+ function asInlineTrait(ref2) {
2017
+ if (typeof ref2 === "object" && ref2 !== null && "stateMachine" in ref2) {
2018
+ return ref2;
2019
+ }
2020
+ return null;
2021
+ }
2022
+ function findRenderUiRoot(orbital, address) {
2023
+ for (const ref2 of orbital.traits) {
2024
+ const trait = asInlineTrait(ref2);
2025
+ if (!trait || trait.name !== address.trait) continue;
2026
+ for (const t of trait.stateMachine?.transitions ?? []) {
2027
+ if (t.event !== address.transition) continue;
2028
+ if (address.state !== void 0 && t.from !== address.state) continue;
2029
+ for (const eff of t.effects ?? []) {
2030
+ const ru = readRenderUi(eff);
2031
+ if (ru && ru.slot === address.slot) return ru.node;
2032
+ }
2033
+ }
2034
+ }
2035
+ return null;
2036
+ }
2037
+ function resolvePath(root, patch) {
2038
+ if (patch.op === "insert") {
2039
+ return navigatePatternPath(root, patch.address.path) ? patch.address.path : null;
2040
+ }
2041
+ const atPath = navigatePatternPath(root, patch.address.path);
2042
+ if (atPath && (patch.fingerprint === void 0 || fingerprintNode(atPath) === patch.fingerprint)) {
2043
+ return patch.address.path;
2044
+ }
2045
+ if (patch.fingerprint !== void 0) {
2046
+ return findByFingerprint(root, "root", patch.fingerprint);
2047
+ }
2048
+ return null;
2049
+ }
2050
+ function applyOnePatch(orbital, patch) {
2051
+ const root = findRenderUiRoot(orbital, patch.address);
2052
+ if (!root) return false;
2053
+ const path = resolvePath(root, patch);
2054
+ if (path === null) return false;
2055
+ switch (patch.op) {
2056
+ case "set-prop":
2057
+ case "rebind":
2058
+ return patch.prop !== void 0 && setPropAtPath(root, path, patch.prop, patch.value);
2059
+ case "remove":
2060
+ return removeChildAtPath(root, path);
2061
+ case "insert":
2062
+ return patch.node !== void 0 && insertChildAtPath(root, path, patch.index ?? Number.MAX_SAFE_INTEGER, patch.node);
2063
+ case "replace": {
2064
+ if (patch.node === void 0) return false;
2065
+ if (path === "root") {
2066
+ const target = navigatePatternPath(root, "root");
2067
+ if (!target) return false;
2068
+ replaceNodeInPlace(target, patch.node);
2069
+ return true;
2070
+ }
2071
+ return replaceChildAtPath(root, path, patch.node);
2072
+ }
2073
+ default:
2074
+ return false;
2075
+ }
2076
+ }
2077
+ function applyRenderOverlay(orbital, patches) {
2078
+ let applied = 0;
2079
+ const stale = [];
2080
+ for (const patch of patches) {
2081
+ if (applyOnePatch(orbital, patch)) {
2082
+ applied += 1;
2083
+ } else {
2084
+ stale.push(patch);
2085
+ }
2086
+ }
2087
+ return { applied, stale };
2088
+ }
2089
+
1900
2090
  // src/resolver.ts
1901
2091
  var schemaCache = /* @__PURE__ */ new WeakMap();
1902
2092
  function clearSchemaCache() {
@@ -2796,8 +2986,28 @@ function buildConfigKeyQuestion(call, trait, param) {
2796
2986
  if (param.tier) {
2797
2987
  out.tier = param.tier;
2798
2988
  }
2989
+ if (param.description) {
2990
+ out.helpText = param.description;
2991
+ }
2992
+ const weight = tierWeight(param.tier);
2993
+ out.weight = weight;
2994
+ out.priority = weight;
2799
2995
  return out;
2800
2996
  }
2997
+ function tierWeight(tier) {
2998
+ switch (tier) {
2999
+ case "domain":
3000
+ case "policy":
3001
+ return 3;
3002
+ case "infra":
3003
+ return 2;
3004
+ case "internal":
3005
+ return 0;
3006
+ case "presentation":
3007
+ default:
3008
+ return 1;
3009
+ }
3010
+ }
2801
3011
  function callSiteOverrideValue(call, traitName, configKey) {
2802
3012
  const override = call.params.traitOverrides?.[traitName];
2803
3013
  if (!override?.config) return void 0;
@@ -2867,7 +3077,10 @@ function capabilityQuestions(call, signature, ruleCapabilities) {
2867
3077
  capability: cap,
2868
3078
  appliesTo: [entityName]
2869
3079
  },
2870
- suggestedAnswers: ["yes", "skip"]
3080
+ suggestedAnswers: ["yes", "skip"],
3081
+ // Capabilities encode governance/policy decisions — high impact.
3082
+ weight: 3,
3083
+ priority: 3
2871
3084
  });
2872
3085
  }
2873
3086
  }
@@ -4040,6 +4253,6 @@ function buildPayloadForEdge(transition, guardCase) {
4040
4253
  return {};
4041
4254
  }
4042
4255
 
4043
- export { AGENT_DOMAIN_CATEGORIES, ALLOWED_CUSTOM_COMPONENTS, AgentDomainCategorySchema, AnimationDefSchema, AssetMapSchema, AssetMappingSchema, BINDING_CONTEXT_RULES, BINDING_DOCS, BINDING_ROOTS, BindingSchema, CORE_BINDINGS, ColorSliceSchema, ColorTokensSchema, ComputedEventContractSchema, ComputedEventListenerSchema, ConfigFieldDeclarationSchema, CustomPatternDefinitionSchema, CustomPatternMapSchema, DEFAULT_INTERACTION_MODELS, DeclaredTraitConfigSchema, DensitySliceSchema, DensityTokensSchema, DesignPreferencesSchema, DesignTokensSchema, DomainCategorySchema, DomainContextSchema, DomainVocabularySchema, ENTITY_ROLES, EffectSchema, ElevationSliceSchema, ElevationTokensSchema, EntityCallSchema, EntityFieldContractSchema, EntityFieldSchema, EntityPersistenceSchema, EntityRefSchema, EntityRefStringSchema, EntityRoleSchema, EntitySchema, EntitySemanticRoleSchema, EventListenerSchema, EventPayloadFieldSchema, EventSchema, EventScopeSchema, EventSemanticRoleSchema, EventSourceSchema, ExpressionSchema, FieldFormatSchema, FieldSchema, FieldTypeSchema, GAME_TYPES, GameSubCategorySchema, GameTypeSchema, GeometrySliceSchema, GeometryTokensSchema, GuardSchema, IconFamilySchema, IconographySliceSchema, IconographyTokensSchema, IllustrationSliceSchema, IllustrationStyleSchema, IllustrationTokensSchema, InteractionModelSchema, KNOWN_VALIDATION_ERROR_CODES, ListenSourceSchema, McpServiceDefSchema, MotionDurationKeySchema, MotionDurationPaletteSchema, MotionEasingKeySchema, MotionEasingPaletteSchema, MotionIntentMapSchema, MotionIntentSchema, MotionSliceSchema, MotionTokensSchema, NodeClassificationSchema, OrbitalConfigSchema, OrbitalDefinitionSchema, OrbitalEntitySchema, OrbitalPageSchema, OrbitalPageStrictSchema, OrbitalSchemaSchema, OrbitalTraitRefSchema, OrbitalUnitSchema, OrbitalSchema as OrbitalZodSchema, PageRefObjectSchema, PageRefSchema, PageRefStringSchema, PageSchema, PageTraitRefSchema, PatternTypeSchema, PayloadFieldSchema, RelatedLinkSchema, RelationConfigSchema, RequiredFieldSchema, ResolvedAssetSchema, RestAuthConfigSchema, RestServiceDefSchema, SERVICE_TYPES, SExprAtomSchema, SExprSchema, SemanticAssetRefSchema, ServiceDefinitionSchema, ServiceRefObjectSchema, ServiceRefSchema, ServiceRefStringSchema, ServiceTypeSchema, SkinSpecSchema, SocketEventsSchema, SocketServiceDefSchema, SpacingScaleSchema, StateMachineSchema, StateSchema, StateSemanticRoleSchema, SuggestedGuardSchema, ThemeDefinitionSchema, ThemeRefSchema, ThemeRefStringSchema, ThemeTokensSchema, ThemeVariantSchema, TraitCategorySchema, TraitConfigSchema, TraitConfigValueSchema, TraitDataEntitySchema, TraitEntityFieldSchema, TraitEventContractSchema, TraitEventListenerSchema, TraitFieldRefSchema, TraitRefSchema, TraitReferenceSchema, TraitSchema, TraitTickSchema, TransitionSchema, TypeIntentMapSchema, TypeIntentSchema, TypeScaleEntrySchema, TypeScaleSchema, TypeScaleTokensSchema, TypeSizeKeySchema, TypeSliceSchema, TypeSlotSchema, TypeWeightSchema, UISlotSchema, UI_SLOTS, UXHintsSchema, UseDeclarationSchema, UserPersonaSchema, VISUAL_STYLES, ViewTypeSchema, VisualStyleSchema, answerToMutations, answersToMutations, applyEventWiring, applyFactoryCallPlanMutation, atomic, buildEdgeCoveringWalk, buildGuardPayloads, buildReplayPaths, buildStateGraph, callService, categorizeRemovals, classifyWorkflow, clearSchemaCache, collectBindings, collectReachableStates, composeBehaviors, createAssetKey, createEmptyResolvedPage, createEmptyResolvedTrait, createLazyService, createResolvedField, createTypedEventBus, deref, deriveCollection, deriveInputType, despawn, detectLayoutStrategy, detectPageContentReduction, diffFactoryCalls, diffOrbitalSchemas, diffSchemaSemantics, diffSchemas, doEffects, emit, extractPayloadFieldRef, findService, generateQuestions, getAllPatternTypes, getArgs, getBindingExamples, getDefaultAnimationsForRole, getEntity, getInteractionModelForDomain, getOperator, getPage, getPages, getRemovals, getSchemaCacheStats, getServiceNames, getTrait, getTraitConfig, getTraitName, hasService, hasSignificantPageReduction, inferTsType, isBinding, isCircuitEvent, isDestructiveChange, isEffect, isEntityCall, isEntityReference, isEntityReferenceAny, isImportedTraitRef, isInlineTrait, isJsonArray, isJsonObject, isJsonPrimitive, isKnownValidationErrorCode, isMcpService, isOrbitalDefinition, isPageReference, isPageReferenceObject, isPageReferenceString, isResolvedIR, isRestService, isRuntimeEntity, isSExpr, isSExprAtom, isSExprCall, isSExprEffect, isServiceReference, isServiceReferenceObject, isSingletonEntity, isSocketService, isThemeReference, isTraitFieldRef, isValidBinding, navigate, normalizeTraitRef, notify, parseAssetKey, parseBinding, parseEntityRef, parseImportedTraitRef, parseOrbitalSchema, parsePageRef, parseServiceRef, persist, ref, renderUI, requiresConfirmation, safeParseOrbitalSchema, schemaToIR, set, sexpr, spawn, summarizeOrbital, summarizeSchema, swap, toBindingRoot, translateOverlaysToParams, validateAssetAnimations, validateBindingInContext, walkSExpr, walkStatePairs, watch, widenTier };
4256
+ export { AGENT_DOMAIN_CATEGORIES, ALLOWED_CUSTOM_COMPONENTS, AgentDomainCategorySchema, AnimationDefSchema, AssetMapSchema, AssetMappingSchema, BINDING_CONTEXT_RULES, BINDING_DOCS, BINDING_ROOTS, BindingSchema, CORE_BINDINGS, ColorSliceSchema, ColorTokensSchema, ComputedEventContractSchema, ComputedEventListenerSchema, ConfigFieldDeclarationSchema, ConfigProvenanceRecordSchema, CustomPatternDefinitionSchema, CustomPatternMapSchema, DEFAULT_INTERACTION_MODELS, DeclaredTraitConfigSchema, DensitySliceSchema, DensityTokensSchema, DesignPreferencesSchema, DesignTokensSchema, DomainCategorySchema, DomainContextSchema, DomainVocabularySchema, ENTITY_ROLES, EffectSchema, ElevationSliceSchema, ElevationTokensSchema, EntityCallSchema, EntityFieldContractSchema, EntityFieldSchema, EntityPersistenceSchema, EntityRefSchema, EntityRefStringSchema, EntityRoleSchema, EntitySchema, EntitySemanticRoleSchema, EventListenerSchema, EventPayloadFieldSchema, EventSchema, EventScopeSchema, EventSemanticRoleSchema, EventSourceSchema, ExpressionSchema, FieldFormatSchema, FieldSchema, FieldTypeSchema, GAME_TYPES, GameSubCategorySchema, GameTypeSchema, GeometrySliceSchema, GeometryTokensSchema, GuardSchema, IconFamilySchema, IconographySliceSchema, IconographyTokensSchema, IllustrationSliceSchema, IllustrationStyleSchema, IllustrationTokensSchema, InteractionModelSchema, KNOWN_VALIDATION_ERROR_CODES, ListenSourceSchema, McpServiceDefSchema, MotionDurationKeySchema, MotionDurationPaletteSchema, MotionEasingKeySchema, MotionEasingPaletteSchema, MotionIntentMapSchema, MotionIntentSchema, MotionSliceSchema, MotionTokensSchema, NodeClassificationSchema, OrbitalConfigSchema, OrbitalDefinitionSchema, OrbitalEntitySchema, OrbitalPageSchema, OrbitalPageStrictSchema, OrbitalSchemaSchema, OrbitalTraitRefSchema, OrbitalUnitSchema, OrbitalSchema as OrbitalZodSchema, PageRefObjectSchema, PageRefSchema, PageRefStringSchema, PageSchema, PageTraitRefSchema, PatternTypeSchema, PayloadFieldSchema, RelatedLinkSchema, RelationConfigSchema, RequiredFieldSchema, ResolvedAssetSchema, RestAuthConfigSchema, RestServiceDefSchema, SERVICE_TYPES, SExprAtomSchema, SExprSchema, SchemaMetadataSchema, SemanticAssetRefSchema, ServiceDefinitionSchema, ServiceRefObjectSchema, ServiceRefSchema, ServiceRefStringSchema, ServiceTypeSchema, SkinSpecSchema, SocketEventsSchema, SocketServiceDefSchema, SpacingScaleSchema, StateMachineSchema, StateSchema, StateSemanticRoleSchema, SuggestedGuardSchema, ThemeDefinitionSchema, ThemeRefSchema, ThemeRefStringSchema, ThemeTokensSchema, ThemeVariantSchema, TraitCategorySchema, TraitConfigSchema, TraitConfigValueSchema, TraitDataEntitySchema, TraitEntityFieldSchema, TraitEventContractSchema, TraitEventListenerSchema, TraitFieldRefSchema, TraitRefSchema, TraitReferenceSchema, TraitSchema, TraitTickSchema, TransitionSchema, TypeIntentMapSchema, TypeIntentSchema, TypeScaleEntrySchema, TypeScaleSchema, TypeScaleTokensSchema, TypeSizeKeySchema, TypeSliceSchema, TypeSlotSchema, TypeWeightSchema, UISlotSchema, UI_SLOTS, UXHintsSchema, UseDeclarationSchema, UserPersonaSchema, VISUAL_STYLES, ViewTypeSchema, VisualStyleSchema, answerToMutations, answersToMutations, applyEventWiring, applyFactoryCallPlanMutation, applyRenderOverlay, atomic, buildEdgeCoveringWalk, buildGuardPayloads, buildReplayPaths, buildStateGraph, callService, categorizeRemovals, classifyWorkflow, clearSchemaCache, collectBindings, collectReachableStates, composeBehaviors, createAssetKey, createEmptyResolvedPage, createEmptyResolvedTrait, createLazyService, createResolvedField, createTypedEventBus, deref, deriveCollection, deriveInputType, despawn, detectLayoutStrategy, detectPageContentReduction, diffFactoryCalls, diffOrbitalSchemas, diffSchemaSemantics, diffSchemas, doEffects, emit, extractPayloadFieldRef, findService, fingerprintNode, generateQuestions, getAllPatternTypes, getArgs, getBindingExamples, getDefaultAnimationsForRole, getEntity, getInteractionModelForDomain, getOperator, getPage, getPages, getRemovals, getSchemaCacheStats, getServiceNames, getTrait, getTraitConfig, getTraitName, hasService, hasSignificantPageReduction, inferTsType, insertChildAtPath, isBinding, isCircuitEvent, isDestructiveChange, isEffect, isEntityCall, isEntityReference, isEntityReferenceAny, isImportedTraitRef, isInlineTrait, isJsonArray, isJsonObject, isJsonPrimitive, isKnownValidationErrorCode, isMcpService, isOrbitalDefinition, isPageReference, isPageReferenceObject, isPageReferenceString, isResolvedIR, isRestService, isRuntimeEntity, isSExpr, isSExprAtom, isSExprCall, isSExprEffect, isServiceReference, isServiceReferenceObject, isSingletonEntity, isSocketService, isThemeReference, isTraitFieldRef, isValidBinding, navigate, navigatePatternPath, normalizeTraitRef, notify, parseAssetKey, parseBinding, parseEntityRef, parseImportedTraitRef, parseOrbitalSchema, parsePageRef, parseServiceRef, persist, ref, removeChildAtPath, renderUI, replaceChildAtPath, requiresConfirmation, safeParseOrbitalSchema, schemaToIR, set, setPropAtPath, sexpr, spawn, summarizeOrbital, summarizeSchema, swap, toBindingRoot, translateOverlaysToParams, validateAssetAnimations, validateBindingInContext, walkSExpr, walkStatePairs, watch, widenTier };
4044
4257
  //# sourceMappingURL=index.js.map
4045
4258
  //# sourceMappingURL=index.js.map