@elevasis/core 0.26.0 → 0.28.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 (49) hide show
  1. package/dist/index.d.ts +162 -105
  2. package/dist/index.js +280 -174
  3. package/dist/knowledge/index.d.ts +43 -43
  4. package/dist/organization-model/index.d.ts +162 -105
  5. package/dist/organization-model/index.js +280 -174
  6. package/dist/test-utils/index.d.ts +20 -20
  7. package/dist/test-utils/index.js +184 -126
  8. package/package.json +3 -3
  9. package/src/_gen/__tests__/__snapshots__/contracts.md.snap +976 -1063
  10. package/src/business/acquisition/api-schemas.test.ts +1962 -1841
  11. package/src/business/acquisition/api-schemas.ts +1461 -1464
  12. package/src/business/acquisition/crm-next-action.test.ts +45 -25
  13. package/src/business/acquisition/crm-next-action.ts +227 -220
  14. package/src/business/acquisition/crm-priority.test.ts +41 -8
  15. package/src/business/acquisition/crm-priority.ts +365 -349
  16. package/src/business/acquisition/crm-state-actions.test.ts +208 -153
  17. package/src/business/acquisition/derive-actions.test.ts +90 -13
  18. package/src/business/acquisition/derive-actions.ts +8 -139
  19. package/src/business/acquisition/ontology-validation.ts +72 -158
  20. package/src/business/pdf/sections/investment.ts +1 -1
  21. package/src/business/pdf/sections/summary-investment.ts +1 -1
  22. package/src/execution/engine/tools/tool-maps.ts +872 -831
  23. package/src/organization-model/__tests__/cross-ref.test.ts +167 -0
  24. package/src/organization-model/__tests__/define-domain-record.test.ts +289 -0
  25. package/src/organization-model/__tests__/om-spine-doc-contract.test.ts +56 -0
  26. package/src/organization-model/__tests__/published-zero-leak.test.ts +60 -1
  27. package/src/organization-model/__tests__/resolve.test.ts +1 -1
  28. package/src/organization-model/__tests__/schema-refinements.test.ts +72 -0
  29. package/src/organization-model/cross-ref.ts +175 -0
  30. package/src/organization-model/domains/actions.ts +13 -0
  31. package/src/organization-model/domains/branding.ts +6 -6
  32. package/src/organization-model/domains/customers.ts +95 -78
  33. package/src/organization-model/domains/entities.ts +157 -144
  34. package/src/organization-model/domains/goals.ts +100 -83
  35. package/src/organization-model/domains/knowledge.ts +106 -93
  36. package/src/organization-model/domains/offerings.ts +88 -71
  37. package/src/organization-model/domains/policies.ts +115 -102
  38. package/src/organization-model/domains/roles.ts +109 -96
  39. package/src/organization-model/domains/sales.test.ts +104 -218
  40. package/src/organization-model/domains/sales.ts +212 -375
  41. package/src/organization-model/domains/statuses.ts +351 -339
  42. package/src/organization-model/domains/systems.ts +176 -164
  43. package/src/organization-model/helpers.ts +331 -306
  44. package/src/organization-model/index.ts +43 -0
  45. package/src/organization-model/published.ts +27 -2
  46. package/src/organization-model/schema-refinements.ts +667 -0
  47. package/src/organization-model/schema.ts +8 -715
  48. package/src/platform/constants/versions.ts +1 -1
  49. package/src/reference/_generated/contracts.md +1000 -1087
@@ -3719,9 +3719,9 @@ declare const SurfaceTypeSchema: z.ZodEnum<{
3719
3719
  dashboard: "dashboard";
3720
3720
  settings: "settings";
3721
3721
  graph: "graph";
3722
- list: "list";
3723
3722
  page: "page";
3724
3723
  detail: "detail";
3724
+ list: "list";
3725
3725
  }>;
3726
3726
  interface SidebarSurfaceNode {
3727
3727
  type: 'surface';
@@ -3929,7 +3929,7 @@ declare const OrganizationModelSchema: z.ZodObject<{
3929
3929
  lastModified: string;
3930
3930
  } | undefined;
3931
3931
  }>>;
3932
- branding: z.ZodObject<{
3932
+ branding: z.ZodDefault<z.ZodObject<{
3933
3933
  organizationName: z.ZodString;
3934
3934
  productName: z.ZodString;
3935
3935
  shortName: z.ZodString;
@@ -3938,7 +3938,7 @@ declare const OrganizationModelSchema: z.ZodObject<{
3938
3938
  light: z.ZodOptional<z.ZodString>;
3939
3939
  dark: z.ZodOptional<z.ZodString>;
3940
3940
  }, z.core.$strip>>;
3941
- }, z.core.$strip>;
3941
+ }, z.core.$strip>>;
3942
3942
  navigation: z.ZodDefault<z.ZodObject<{
3943
3943
  sidebar: z.ZodDefault<z.ZodObject<{
3944
3944
  primary: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodType<SidebarNode, unknown, z.core.$ZodTypeInternals<SidebarNode, unknown>>>>;
@@ -4159,8 +4159,8 @@ declare const OrganizationModelSchema: z.ZodObject<{
4159
4159
  description: z.ZodOptional<z.ZodString>;
4160
4160
  ownerRoleId: z.ZodOptional<z.ZodString>;
4161
4161
  status: z.ZodEnum<{
4162
- deprecated: "deprecated";
4163
4162
  active: "active";
4163
+ deprecated: "deprecated";
4164
4164
  archived: "archived";
4165
4165
  }>;
4166
4166
  ontology: z.ZodOptional<z.ZodObject<{
@@ -4178,12 +4178,12 @@ declare const OrganizationModelSchema: z.ZodObject<{
4178
4178
  codeRefs: z.ZodDefault<z.ZodArray<z.ZodObject<{
4179
4179
  path: z.ZodString;
4180
4180
  role: z.ZodEnum<{
4181
- config: "config";
4182
4181
  entrypoint: "entrypoint";
4183
4182
  handler: "handler";
4184
4183
  schema: "schema";
4185
4184
  test: "test";
4186
4185
  docs: "docs";
4186
+ config: "config";
4187
4187
  }>;
4188
4188
  symbol: z.ZodOptional<z.ZodString>;
4189
4189
  description: z.ZodOptional<z.ZodString>;
@@ -4194,10 +4194,10 @@ declare const OrganizationModelSchema: z.ZodObject<{
4194
4194
  label: z.ZodString;
4195
4195
  payloadSchema: z.ZodOptional<z.ZodString>;
4196
4196
  lifecycle: z.ZodOptional<z.ZodEnum<{
4197
+ active: "active";
4197
4198
  deprecated: "deprecated";
4198
4199
  draft: "draft";
4199
4200
  beta: "beta";
4200
- active: "active";
4201
4201
  archived: "archived";
4202
4202
  }>>;
4203
4203
  }, z.core.$strip>>>;
@@ -4209,8 +4209,8 @@ declare const OrganizationModelSchema: z.ZodObject<{
4209
4209
  description: z.ZodOptional<z.ZodString>;
4210
4210
  ownerRoleId: z.ZodOptional<z.ZodString>;
4211
4211
  status: z.ZodEnum<{
4212
- deprecated: "deprecated";
4213
4212
  active: "active";
4213
+ deprecated: "deprecated";
4214
4214
  archived: "archived";
4215
4215
  }>;
4216
4216
  ontology: z.ZodOptional<z.ZodObject<{
@@ -4228,12 +4228,12 @@ declare const OrganizationModelSchema: z.ZodObject<{
4228
4228
  codeRefs: z.ZodDefault<z.ZodArray<z.ZodObject<{
4229
4229
  path: z.ZodString;
4230
4230
  role: z.ZodEnum<{
4231
- config: "config";
4232
4231
  entrypoint: "entrypoint";
4233
4232
  handler: "handler";
4234
4233
  schema: "schema";
4235
4234
  test: "test";
4236
4235
  docs: "docs";
4236
+ config: "config";
4237
4237
  }>;
4238
4238
  symbol: z.ZodOptional<z.ZodString>;
4239
4239
  description: z.ZodOptional<z.ZodString>;
@@ -4275,10 +4275,10 @@ declare const OrganizationModelSchema: z.ZodObject<{
4275
4275
  label: z.ZodString;
4276
4276
  payloadSchema: z.ZodOptional<z.ZodString>;
4277
4277
  lifecycle: z.ZodOptional<z.ZodEnum<{
4278
+ active: "active";
4278
4279
  deprecated: "deprecated";
4279
4280
  draft: "draft";
4280
4281
  beta: "beta";
4281
- active: "active";
4282
4282
  archived: "archived";
4283
4283
  }>>;
4284
4284
  }, z.core.$strip>>>;
@@ -4290,8 +4290,8 @@ declare const OrganizationModelSchema: z.ZodObject<{
4290
4290
  description: z.ZodOptional<z.ZodString>;
4291
4291
  ownerRoleId: z.ZodOptional<z.ZodString>;
4292
4292
  status: z.ZodEnum<{
4293
- deprecated: "deprecated";
4294
4293
  active: "active";
4294
+ deprecated: "deprecated";
4295
4295
  archived: "archived";
4296
4296
  }>;
4297
4297
  ontology: z.ZodOptional<z.ZodObject<{
@@ -4309,12 +4309,12 @@ declare const OrganizationModelSchema: z.ZodObject<{
4309
4309
  codeRefs: z.ZodDefault<z.ZodArray<z.ZodObject<{
4310
4310
  path: z.ZodString;
4311
4311
  role: z.ZodEnum<{
4312
- config: "config";
4313
4312
  entrypoint: "entrypoint";
4314
4313
  handler: "handler";
4315
4314
  schema: "schema";
4316
4315
  test: "test";
4317
4316
  docs: "docs";
4317
+ config: "config";
4318
4318
  }>;
4319
4319
  symbol: z.ZodOptional<z.ZodString>;
4320
4320
  description: z.ZodOptional<z.ZodString>;
@@ -4329,8 +4329,8 @@ declare const OrganizationModelSchema: z.ZodObject<{
4329
4329
  description: z.ZodOptional<z.ZodString>;
4330
4330
  ownerRoleId: z.ZodOptional<z.ZodString>;
4331
4331
  status: z.ZodEnum<{
4332
- deprecated: "deprecated";
4333
4332
  active: "active";
4333
+ deprecated: "deprecated";
4334
4334
  archived: "archived";
4335
4335
  }>;
4336
4336
  ontology: z.ZodOptional<z.ZodObject<{
@@ -4348,12 +4348,12 @@ declare const OrganizationModelSchema: z.ZodObject<{
4348
4348
  codeRefs: z.ZodDefault<z.ZodArray<z.ZodObject<{
4349
4349
  path: z.ZodString;
4350
4350
  role: z.ZodEnum<{
4351
- config: "config";
4352
4351
  entrypoint: "entrypoint";
4353
4352
  handler: "handler";
4354
4353
  schema: "schema";
4355
4354
  test: "test";
4356
4355
  docs: "docs";
4356
+ config: "config";
4357
4357
  }>;
4358
4358
  symbol: z.ZodOptional<z.ZodString>;
4359
4359
  description: z.ZodOptional<z.ZodString>;
@@ -4398,9 +4398,9 @@ declare const OrganizationModelSchema: z.ZodObject<{
4398
4398
  id: z.ZodString;
4399
4399
  }, z.core.$strip>], "kind">;
4400
4400
  kind: z.ZodEnum<{
4401
+ approval: "approval";
4401
4402
  triggers: "triggers";
4402
4403
  uses: "uses";
4403
- approval: "approval";
4404
4404
  }>;
4405
4405
  to: z.ZodDiscriminatedUnion<[z.ZodObject<{
4406
4406
  kind: z.ZodLiteral<"system">;
@@ -4467,10 +4467,10 @@ declare const OrganizationModelSchema: z.ZodObject<{
4467
4467
  }, z.core.$strip>], "kind">>>;
4468
4468
  knowledge: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString>>>;
4469
4469
  lifecycle: z.ZodDefault<z.ZodEnum<{
4470
+ active: "active";
4470
4471
  deprecated: "deprecated";
4471
4472
  draft: "draft";
4472
4473
  beta: "beta";
4473
- active: "active";
4474
4474
  archived: "archived";
4475
4475
  }>>;
4476
4476
  }, z.core.$strip>>>>;
@@ -4548,10 +4548,10 @@ declare const OrganizationModelSchema: z.ZodObject<{
4548
4548
  roleIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
4549
4549
  }, z.core.$strip>>;
4550
4550
  lifecycle: z.ZodDefault<z.ZodEnum<{
4551
+ active: "active";
4551
4552
  deprecated: "deprecated";
4552
4553
  draft: "draft";
4553
4554
  beta: "beta";
4554
- active: "active";
4555
4555
  archived: "archived";
4556
4556
  }>>;
4557
4557
  }, z.core.$strip>>>>;
@@ -4634,12 +4634,12 @@ declare const OrganizationModelSchema: z.ZodObject<{
4634
4634
  kind: z.ZodEnum<{
4635
4635
  knowledge: "knowledge";
4636
4636
  system: "system";
4637
+ resource: "resource";
4637
4638
  action: "action";
4638
4639
  ontology: "ontology";
4639
4640
  role: "role";
4640
- goal: "goal";
4641
- resource: "resource";
4642
4641
  stage: "stage";
4642
+ goal: "goal";
4643
4643
  "customer-segment": "customer-segment";
4644
4644
  offering: "offering";
4645
4645
  }>;
@@ -4649,7 +4649,7 @@ declare const OrganizationModelSchema: z.ZodObject<{
4649
4649
  nodeId: z.ZodUnion<readonly [z.ZodString, z.ZodTemplateLiteral<`ontology:${string}`>]>;
4650
4650
  }, z.core.$strip>]>, z.ZodTransform<{
4651
4651
  target: {
4652
- kind: "knowledge" | "system" | "action" | "ontology" | "role" | "goal" | "resource" | "stage" | "customer-segment" | "offering";
4652
+ kind: "knowledge" | "system" | "resource" | "action" | "ontology" | "role" | "stage" | "goal" | "customer-segment" | "offering";
4653
4653
  id: string;
4654
4654
  };
4655
4655
  nodeId: string;
@@ -4657,7 +4657,7 @@ declare const OrganizationModelSchema: z.ZodObject<{
4657
4657
  nodeId: string;
4658
4658
  } | {
4659
4659
  target: {
4660
- kind: "knowledge" | "system" | "action" | "ontology" | "role" | "goal" | "resource" | "stage" | "customer-segment" | "offering";
4660
+ kind: "knowledge" | "system" | "resource" | "action" | "ontology" | "role" | "stage" | "goal" | "customer-segment" | "offering";
4661
4661
  id: string;
4662
4662
  };
4663
4663
  }>>>>;
@@ -19906,8 +19906,8 @@ var OrganizationModelBrandingSchema = z.object({
19906
19906
  });
19907
19907
  var DEFAULT_ORGANIZATION_MODEL_BRANDING = {
19908
19908
  organizationName: "Default Organization",
19909
- productName: "Elevasis",
19910
- shortName: "Elevasis",
19909
+ productName: "Organization OS",
19910
+ shortName: "Org OS",
19911
19911
  logos: {}
19912
19912
  };
19913
19913
  var SurfaceTypeSchema = z.enum(["page", "dashboard", "graph", "detail", "list", "settings"]).meta({ label: "Surface type", color: "blue" });
@@ -20036,6 +20036,28 @@ var DEFAULT_ORGANIZATION_MODEL_IDENTITY = {
20036
20036
  businessHours: {},
20037
20037
  clientBrief: ""
20038
20038
  };
20039
+
20040
+ // src/organization-model/helpers.ts
20041
+ function childSystemsOf2(system) {
20042
+ return system.systems ?? system.subsystems ?? {};
20043
+ }
20044
+ function listAllSystems(model) {
20045
+ const results = [];
20046
+ function walk(map2, prefix) {
20047
+ for (const [localId, system] of Object.entries(map2)) {
20048
+ const fullPath = prefix ? `${prefix}.${localId}` : localId;
20049
+ results.push({ path: fullPath, system });
20050
+ const childSystems = childSystemsOf2(system);
20051
+ if (Object.keys(childSystems).length > 0) {
20052
+ walk(childSystems, fullPath);
20053
+ }
20054
+ }
20055
+ }
20056
+ walk(model.systems, "");
20057
+ return results;
20058
+ }
20059
+
20060
+ // src/organization-model/domains/customers.ts
20039
20061
  var FirmographicsSchema = z.object({
20040
20062
  /** Industry vertical (e.g. "Marketing Agency", "Legal", "Real Estate"). */
20041
20063
  industry: z.string().trim().max(200).optional(),
@@ -20879,79 +20901,86 @@ var PoliciesDomainSchema = z.record(z.string(), PolicySchema).refine((record) =>
20879
20901
  }).default({});
20880
20902
  var DEFAULT_ORGANIZATION_MODEL_POLICIES = {};
20881
20903
 
20882
- // src/organization-model/schema.ts
20883
- z.enum([
20884
- "branding",
20885
- "identity",
20886
- "customers",
20887
- "offerings",
20888
- "roles",
20889
- "goals",
20890
- "systems",
20891
- "ontology",
20892
- "resources",
20893
- "topology",
20894
- "actions",
20895
- "entities",
20896
- "policies",
20897
- "knowledge"
20898
- ]);
20899
- var OrganizationModelDomainMetadataSchema = z.object({
20900
- version: z.literal(1).default(1),
20901
- lastModified: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "lastModified must be an ISO date string (YYYY-MM-DD)")
20902
- });
20903
- var DEFAULT_ORGANIZATION_MODEL_DOMAIN_METADATA = {
20904
- branding: { version: 1, lastModified: "2026-05-10" },
20905
- identity: { version: 1, lastModified: "2026-05-10" },
20906
- customers: { version: 1, lastModified: "2026-05-10" },
20907
- offerings: { version: 1, lastModified: "2026-05-10" },
20908
- roles: { version: 1, lastModified: "2026-05-10" },
20909
- goals: { version: 1, lastModified: "2026-05-10" },
20910
- systems: { version: 1, lastModified: "2026-05-10" },
20911
- ontology: { version: 1, lastModified: "2026-05-14" },
20912
- resources: { version: 1, lastModified: "2026-05-10" },
20913
- topology: { version: 1, lastModified: "2026-05-14" },
20914
- actions: { version: 1, lastModified: "2026-05-10" },
20915
- entities: { version: 1, lastModified: "2026-05-10" },
20916
- policies: { version: 1, lastModified: "2026-05-10" },
20917
- knowledge: { version: 1, lastModified: "2026-05-10" }
20904
+ // src/organization-model/cross-ref.ts
20905
+ var ONTOLOGY_REFERENCE_KEY_KINDS = {
20906
+ valueType: "value-type",
20907
+ catalogType: "catalog",
20908
+ objectType: "object",
20909
+ eventType: "event",
20910
+ actionType: "action",
20911
+ linkType: "link",
20912
+ interfaceType: "interface",
20913
+ propertyType: "property",
20914
+ groupType: "group",
20915
+ surfaceType: "surface",
20916
+ stepCatalog: "catalog"
20918
20917
  };
20919
- var OrganizationModelDomainMetadataByDomainSchema = z.object({
20920
- branding: OrganizationModelDomainMetadataSchema,
20921
- identity: OrganizationModelDomainMetadataSchema,
20922
- customers: OrganizationModelDomainMetadataSchema,
20923
- offerings: OrganizationModelDomainMetadataSchema,
20924
- roles: OrganizationModelDomainMetadataSchema,
20925
- goals: OrganizationModelDomainMetadataSchema,
20926
- systems: OrganizationModelDomainMetadataSchema,
20927
- ontology: OrganizationModelDomainMetadataSchema,
20928
- resources: OrganizationModelDomainMetadataSchema,
20929
- topology: OrganizationModelDomainMetadataSchema,
20930
- actions: OrganizationModelDomainMetadataSchema,
20931
- entities: OrganizationModelDomainMetadataSchema,
20932
- policies: OrganizationModelDomainMetadataSchema,
20933
- knowledge: OrganizationModelDomainMetadataSchema
20934
- }).partial().default(DEFAULT_ORGANIZATION_MODEL_DOMAIN_METADATA).transform((metadata) => ({ ...DEFAULT_ORGANIZATION_MODEL_DOMAIN_METADATA, ...metadata }));
20935
- var OrganizationModelSchemaBase = z.object({
20936
- version: z.literal(1).default(1),
20937
- domainMetadata: OrganizationModelDomainMetadataByDomainSchema,
20938
- branding: OrganizationModelBrandingSchema,
20939
- navigation: OrganizationModelNavigationSchema,
20940
- identity: IdentityDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_IDENTITY),
20941
- customers: CustomersDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_CUSTOMERS),
20942
- offerings: OfferingsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_OFFERINGS),
20943
- roles: RolesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_ROLES),
20944
- goals: GoalsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_GOALS),
20945
- systems: SystemsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_SYSTEMS),
20946
- ontology: OntologyScopeSchema.default(DEFAULT_ONTOLOGY_SCOPE),
20947
- resources: ResourcesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_RESOURCES),
20948
- topology: OmTopologyDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_TOPOLOGY),
20949
- actions: ActionsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_ACTIONS),
20950
- entities: EntitiesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_ENTITIES),
20951
- policies: PoliciesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_POLICIES),
20952
- // D3: flat Record<id, OrgKnowledgeNode> — no wrapper object
20953
- knowledge: KnowledgeDomainSchema.default({})
20954
- });
20918
+ function buildOmCrossRefIndex(model) {
20919
+ const systemsById = /* @__PURE__ */ new Map();
20920
+ for (const { path, system } of listAllSystems(model)) {
20921
+ systemsById.set(path, system);
20922
+ systemsById.set(system.id, system);
20923
+ }
20924
+ const resourceIds = new Set(Object.keys(model.resources ?? {}));
20925
+ const knowledgeIds = new Set(Object.keys(model.knowledge ?? {}));
20926
+ const roleIds = new Set(Object.keys(model.roles ?? {}));
20927
+ const goalIds = new Set(Object.keys(model.goals ?? {}));
20928
+ const actionIds = new Set(Object.keys(model.actions ?? {}));
20929
+ const customerSegmentIds = new Set(Object.keys(model.customers ?? {}));
20930
+ const offeringIds = new Set(Object.keys(model.offerings ?? {}));
20931
+ const ontologyCompilation = compileOrganizationOntology(model);
20932
+ const ontologyIndexByKind = {
20933
+ object: ontologyCompilation.ontology.objectTypes,
20934
+ link: ontologyCompilation.ontology.linkTypes,
20935
+ action: ontologyCompilation.ontology.actionTypes,
20936
+ catalog: ontologyCompilation.ontology.catalogTypes,
20937
+ event: ontologyCompilation.ontology.eventTypes,
20938
+ interface: ontologyCompilation.ontology.interfaceTypes,
20939
+ "value-type": ontologyCompilation.ontology.valueTypes,
20940
+ property: ontologyCompilation.ontology.sharedProperties,
20941
+ group: ontologyCompilation.ontology.groups,
20942
+ surface: ontologyCompilation.ontology.surfaces
20943
+ };
20944
+ const ontologyIds = new Set(Object.values(ontologyIndexByKind).flatMap((index2) => Object.keys(index2)));
20945
+ const stageIds = /* @__PURE__ */ new Set();
20946
+ for (const catalog of Object.values(ontologyCompilation.ontology.catalogTypes)) {
20947
+ if (catalog.kind !== "stage") continue;
20948
+ const entries = catalog.entries;
20949
+ if (entries !== void 0) {
20950
+ for (const stageId of Object.keys(entries)) {
20951
+ stageIds.add(stageId);
20952
+ }
20953
+ }
20954
+ }
20955
+ return {
20956
+ systemsById,
20957
+ resourceIds,
20958
+ knowledgeIds,
20959
+ roleIds,
20960
+ goalIds,
20961
+ actionIds,
20962
+ customerSegmentIds,
20963
+ offeringIds,
20964
+ ontologyIds,
20965
+ ontologyIndexByKind,
20966
+ stageIds
20967
+ };
20968
+ }
20969
+ function knowledgeTargetExists(index2, kind, id) {
20970
+ if (kind === "system") return index2.systemsById.has(id);
20971
+ if (kind === "resource") return index2.resourceIds.has(id);
20972
+ if (kind === "knowledge") return index2.knowledgeIds.has(id);
20973
+ if (kind === "stage") return index2.stageIds.has(id);
20974
+ if (kind === "action") return index2.actionIds.has(id);
20975
+ if (kind === "role") return index2.roleIds.has(id);
20976
+ if (kind === "goal") return index2.goalIds.has(id);
20977
+ if (kind === "customer-segment") return index2.customerSegmentIds.has(id);
20978
+ if (kind === "offering") return index2.offeringIds.has(id);
20979
+ if (kind === "ontology") return index2.ontologyIds.has(id);
20980
+ return false;
20981
+ }
20982
+
20983
+ // src/organization-model/schema-refinements.ts
20955
20984
  function addIssue(ctx, path, message) {
20956
20985
  ctx.addIssue({
20957
20986
  code: z.ZodIssueCode.custom,
@@ -20982,7 +21011,7 @@ function isKnowledgeKindCompatibleWithTarget(knowledgeKind, targetKind) {
20982
21011
  function isRecord(value) {
20983
21012
  return typeof value === "object" && value !== null && !Array.isArray(value);
20984
21013
  }
20985
- var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ctx) => {
21014
+ function refineOrganizationModel(model, ctx) {
20986
21015
  function collectAllSystems(systems, prefix = "", schemaPath = ["systems"]) {
20987
21016
  const result = [];
20988
21017
  for (const [key, system] of Object.entries(systems)) {
@@ -21154,7 +21183,7 @@ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ct
21154
21183
  });
21155
21184
  });
21156
21185
  Object.values(model.entities).forEach((entity) => {
21157
- if (!systemsById.has(entity.ownedBySystemId)) {
21186
+ if (systemsById.size > 0 && !systemsById.has(entity.ownedBySystemId)) {
21158
21187
  addIssue(
21159
21188
  ctx,
21160
21189
  ["entities", entity.id, "ownedBySystemId"],
@@ -21272,29 +21301,9 @@ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ct
21272
21301
  }
21273
21302
  });
21274
21303
  });
21275
- const actionIds = new Set(Object.keys(model.actions));
21276
- const offeringsById = new Map(Object.entries(model.offerings));
21304
+ const idx = buildOmCrossRefIndex(model);
21305
+ const { ontologyIndexByKind, ontologyIds } = idx;
21277
21306
  const ontologyCompilation = compileOrganizationOntology(model);
21278
- const stageIds = /* @__PURE__ */ new Set();
21279
- for (const catalog of Object.values(ontologyCompilation.ontology.catalogTypes)) {
21280
- if (catalog.kind !== "stage") continue;
21281
- for (const stageId of Object.keys(catalog.entries ?? {})) {
21282
- stageIds.add(stageId);
21283
- }
21284
- }
21285
- const ontologyIndexByKind = {
21286
- object: ontologyCompilation.ontology.objectTypes,
21287
- link: ontologyCompilation.ontology.linkTypes,
21288
- action: ontologyCompilation.ontology.actionTypes,
21289
- catalog: ontologyCompilation.ontology.catalogTypes,
21290
- event: ontologyCompilation.ontology.eventTypes,
21291
- interface: ontologyCompilation.ontology.interfaceTypes,
21292
- "value-type": ontologyCompilation.ontology.valueTypes,
21293
- property: ontologyCompilation.ontology.sharedProperties,
21294
- group: ontologyCompilation.ontology.groups,
21295
- surface: ontologyCompilation.ontology.surfaces
21296
- };
21297
- const ontologyIds = new Set(Object.values(ontologyIndexByKind).flatMap((index2) => Object.keys(index2)));
21298
21307
  function topologyTargetExists(ref) {
21299
21308
  if (ref.kind === "system") return systemsById.has(ref.id);
21300
21309
  if (ref.kind === "resource") return resourcesById.has(ref.id);
@@ -21314,19 +21323,6 @@ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ct
21314
21323
  );
21315
21324
  });
21316
21325
  });
21317
- const ontologyReferenceKeyKinds = {
21318
- valueType: "value-type",
21319
- catalogType: "catalog",
21320
- objectType: "object",
21321
- eventType: "event",
21322
- actionType: "action",
21323
- linkType: "link",
21324
- interfaceType: "interface",
21325
- propertyType: "property",
21326
- groupType: "group",
21327
- surfaceType: "surface",
21328
- stepCatalog: "catalog"
21329
- };
21330
21326
  function validateKnownOntologyReferences(ownerId, value, path, seen = /* @__PURE__ */ new WeakSet()) {
21331
21327
  if (Array.isArray(value)) {
21332
21328
  value.forEach((entry, index2) => validateKnownOntologyReferences(ownerId, entry, [...path, index2], seen));
@@ -21336,7 +21332,7 @@ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ct
21336
21332
  if (seen.has(value)) return;
21337
21333
  seen.add(value);
21338
21334
  Object.entries(value).forEach(([key, entry]) => {
21339
- const expectedKind = ontologyReferenceKeyKinds[key];
21335
+ const expectedKind = ONTOLOGY_REFERENCE_KEY_KINDS[key];
21340
21336
  if (expectedKind !== void 0) {
21341
21337
  if (typeof entry !== "string") {
21342
21338
  addIssue(ctx, [...path, key], `Ontology record "${ownerId}" ${key} must be an ontology ID string`);
@@ -21397,22 +21393,9 @@ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ct
21397
21393
  );
21398
21394
  }
21399
21395
  });
21400
- function knowledgeTargetExists(kind, id) {
21401
- if (kind === "system") return systemsById.has(id);
21402
- if (kind === "resource") return resourcesById.has(id);
21403
- if (kind === "knowledge") return knowledgeById.has(id);
21404
- if (kind === "stage") return stageIds.has(id);
21405
- if (kind === "action") return actionIds.has(id);
21406
- if (kind === "role") return rolesById.has(id);
21407
- if (kind === "goal") return goalsById.has(id);
21408
- if (kind === "customer-segment") return segmentsById.has(id);
21409
- if (kind === "offering") return offeringsById.has(id);
21410
- if (kind === "ontology") return ontologyIds.has(id);
21411
- return false;
21412
- }
21413
21396
  Object.entries(model.knowledge).forEach(([nodeId, node]) => {
21414
21397
  node.links.forEach((link, linkIndex) => {
21415
- if (!knowledgeTargetExists(link.target.kind, link.target.id)) {
21398
+ if (!knowledgeTargetExists(idx, link.target.kind, link.target.id)) {
21416
21399
  addIssue(
21417
21400
  ctx,
21418
21401
  ["knowledge", nodeId, "links", linkIndex, "target"],
@@ -21526,7 +21509,82 @@ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ct
21526
21509
  for (const diagnostic of ontologyCompilation.diagnostics) {
21527
21510
  addIssue(ctx, diagnostic.path, diagnostic.message);
21528
21511
  }
21512
+ }
21513
+
21514
+ // src/organization-model/schema.ts
21515
+ z.enum([
21516
+ "branding",
21517
+ "identity",
21518
+ "customers",
21519
+ "offerings",
21520
+ "roles",
21521
+ "goals",
21522
+ "systems",
21523
+ "ontology",
21524
+ "resources",
21525
+ "topology",
21526
+ "actions",
21527
+ "entities",
21528
+ "policies",
21529
+ "knowledge"
21530
+ ]);
21531
+ var OrganizationModelDomainMetadataSchema = z.object({
21532
+ version: z.literal(1).default(1),
21533
+ lastModified: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "lastModified must be an ISO date string (YYYY-MM-DD)")
21534
+ });
21535
+ var DEFAULT_ORGANIZATION_MODEL_DOMAIN_METADATA = {
21536
+ branding: { version: 1, lastModified: "2026-05-10" },
21537
+ identity: { version: 1, lastModified: "2026-05-10" },
21538
+ customers: { version: 1, lastModified: "2026-05-10" },
21539
+ offerings: { version: 1, lastModified: "2026-05-10" },
21540
+ roles: { version: 1, lastModified: "2026-05-10" },
21541
+ goals: { version: 1, lastModified: "2026-05-10" },
21542
+ systems: { version: 1, lastModified: "2026-05-10" },
21543
+ ontology: { version: 1, lastModified: "2026-05-14" },
21544
+ resources: { version: 1, lastModified: "2026-05-10" },
21545
+ topology: { version: 1, lastModified: "2026-05-14" },
21546
+ actions: { version: 1, lastModified: "2026-05-10" },
21547
+ entities: { version: 1, lastModified: "2026-05-10" },
21548
+ policies: { version: 1, lastModified: "2026-05-10" },
21549
+ knowledge: { version: 1, lastModified: "2026-05-10" }
21550
+ };
21551
+ var OrganizationModelDomainMetadataByDomainSchema = z.object({
21552
+ branding: OrganizationModelDomainMetadataSchema,
21553
+ identity: OrganizationModelDomainMetadataSchema,
21554
+ customers: OrganizationModelDomainMetadataSchema,
21555
+ offerings: OrganizationModelDomainMetadataSchema,
21556
+ roles: OrganizationModelDomainMetadataSchema,
21557
+ goals: OrganizationModelDomainMetadataSchema,
21558
+ systems: OrganizationModelDomainMetadataSchema,
21559
+ ontology: OrganizationModelDomainMetadataSchema,
21560
+ resources: OrganizationModelDomainMetadataSchema,
21561
+ topology: OrganizationModelDomainMetadataSchema,
21562
+ actions: OrganizationModelDomainMetadataSchema,
21563
+ entities: OrganizationModelDomainMetadataSchema,
21564
+ policies: OrganizationModelDomainMetadataSchema,
21565
+ knowledge: OrganizationModelDomainMetadataSchema
21566
+ }).partial().default(DEFAULT_ORGANIZATION_MODEL_DOMAIN_METADATA).transform((metadata) => ({ ...DEFAULT_ORGANIZATION_MODEL_DOMAIN_METADATA, ...metadata }));
21567
+ var OrganizationModelSchemaBase = z.object({
21568
+ version: z.literal(1).default(1),
21569
+ domainMetadata: OrganizationModelDomainMetadataByDomainSchema,
21570
+ branding: OrganizationModelBrandingSchema.default(DEFAULT_ORGANIZATION_MODEL_BRANDING),
21571
+ navigation: OrganizationModelNavigationSchema,
21572
+ identity: IdentityDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_IDENTITY),
21573
+ customers: CustomersDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_CUSTOMERS),
21574
+ offerings: OfferingsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_OFFERINGS),
21575
+ roles: RolesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_ROLES),
21576
+ goals: GoalsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_GOALS),
21577
+ systems: SystemsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_SYSTEMS),
21578
+ ontology: OntologyScopeSchema.default(DEFAULT_ONTOLOGY_SCOPE),
21579
+ resources: ResourcesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_RESOURCES),
21580
+ topology: OmTopologyDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_TOPOLOGY),
21581
+ actions: ActionsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_ACTIONS),
21582
+ entities: EntitiesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_ENTITIES),
21583
+ policies: PoliciesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_POLICIES),
21584
+ // D3: flat Record<id, OrgKnowledgeNode> — no wrapper object
21585
+ knowledge: KnowledgeDomainSchema.default({})
21529
21586
  });
21587
+ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine(refineOrganizationModel);
21530
21588
 
21531
21589
  // src/organization-model/defaults.ts
21532
21590
  var DEFAULT_ORGANIZATION_MODEL_KNOWLEDGE = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elevasis/core",
3
- "version": "0.26.0",
3
+ "version": "0.28.0",
4
4
  "license": "MIT",
5
5
  "description": "Minimal shared constants across Elevasis monorepo",
6
6
  "sideEffects": false,
@@ -41,8 +41,8 @@
41
41
  "rollup-plugin-dts": "^6.3.0",
42
42
  "tsup": "^8.0.0",
43
43
  "typescript": "5.9.2",
44
- "@repo/eslint-config": "0.0.0",
45
- "@repo/typescript-config": "0.0.0"
44
+ "@repo/typescript-config": "0.0.0",
45
+ "@repo/eslint-config": "0.0.0"
46
46
  },
47
47
  "dependencies": {
48
48
  "@anthropic-ai/sdk": "^0.62.0",